I have just started to play with Spring MVC. I installed Intellij Idea and Tomcat server and then created a new project from SpringMVC template. When I run it I got the error:
Servlet.init() for servlet mvc-dispatcher threw exception
I solved it by changing Java jdk from version 1.8 to 1.7. When I run it then, I got this error:
java.lang.ClassNotFoundException: org.apache.jsp.WEB_002dINF.pages.hello_jsp
To fix it I had to remove:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
from my pom.xml file and now it's working. Can someone tell me why this template won't work without these changes?
Without more detail about the error you got, I can't answer why you needed to change the Java version.
As for the servlet-api
dependency, that is because Tomcat has its own implementation of the servlet-api
included. So there was a clash. What you will want to do is add the dependency back into your POM with a scope of provided
. That way it is there for your IDE to use as well as at build time. (Unless of course you are getting the servlet-api
from some where else such as the javaee-api
dependency).
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With