DispatcherServlet Class Not Found Exception Again and Again

I have created a Spring MVC project where I used: jakarta 6.0 and spring-webmvc 6.2 in pom.xml Dynamic Web Module 5 JDK 23 I configured the Dispatcher Servlet in web.xml, then set up the View Resolver in spring-servlet.xml. After that, I created a Controller and placed index.jsp inside the WEB-INF/views/ folder. The server starts successfully, but I always get a 404 error: "The origin server did not find a current representation for the target resource or is not willing to disclose that one exists." Here is my console Output Attached too
15 Replies
JavaBot
JavaBot3w ago
This post has been reserved for your question.
Hey @Mohd Waqar! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
Waqarrrrrr
WaqarrrrrrOP3w ago
@dan1st | Daniel Look at this bro
dan1st
dan1st3w ago
Can you show your pom.xml?
Waqarrrrrr
WaqarrrrrrOP3w ago
Ok
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.spring.mvc</groupId>
<artifactId>springmvc</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>springmvc Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>6.0.0</version> <!-- Check your Tomcat version -->
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>6.2.0</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>springmvc</finalName>
</build>
</project>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.spring.mvc</groupId>
<artifactId>springmvc</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>springmvc Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>6.0.0</version> <!-- Check your Tomcat version -->
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>6.2.0</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>springmvc</finalName>
</build>
</project>
dan1st
dan1st3w ago
So you are using Servlet 6 - then you'd probably want to use Dynamic Web Module 6 that should normally correspond to your servlet version check your web.xml for that - is there a verssion=5 maybe? that wouldn't solve your problem but it would be something off
Waqarrrrrr
WaqarrrrrrOP3w ago
this is my web xml where the version is 6
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="https://jakarta.ee/xml/ns/jakartaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_6_0.xsd"
version="6.0"
metadata-complete="true">

<display-name>Spring MVC Web Application</display-name>

<!-- DispatcherServlet Configuration -->
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

</web-app>
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="https://jakarta.ee/xml/ns/jakartaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_6_0.xsd"
version="6.0"
metadata-complete="true">

<display-name>Spring MVC Web Application</display-name>

<!-- DispatcherServlet Configuration -->
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

</web-app>
dan1st
dan1st3w ago
then you should use version 6 for Dynamic Web Module
dan1st
dan1st3w ago
Anyway for your specific problem: https://stackoverflow.com/q/11227395/10871900 Note: The non Maven answers are probably not relevant
Stack Overflow
java.lang.ClassNotFoundException: org.springframework.web.servlet.D...
i am using spring 3.1.0.RELEASE, and my servlet container is tomcat 7 and my IDE is eclipse indigo and the jar spring-webmvc-3.1.0.RELEASE.jar which contains the DispatcherServlet exists in the lib
dan1st
dan1st3w ago
For example one answer suggests adding Spring Context:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>6.2.0</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>6.2.0</version>
</dependency>
Waqarrrrrr
WaqarrrrrrOP3w ago
okay i am adding it
dan1st
dan1st3w ago
and make sure your dependencies are actually invluded with tomcat
dan1st
dan1st3w ago
Stack Overflow
java.lang.ClassNotFoundException: org.springframework.web.servlet.D...
i am using spring 3.1.0.RELEASE, and my servlet container is tomcat 7 and my IDE is eclipse indigo and the jar spring-webmvc-3.1.0.RELEASE.jar which contains the DispatcherServlet exists in the lib
dan1st
dan1st3w ago
and there's also this self-answer from the OP: https://stackoverflow.com/a/11241159/10871900
Stack Overflow
java.lang.ClassNotFoundException: org.springframework.web.servlet.D...
i am using spring 3.1.0.RELEASE, and my servlet container is tomcat 7 and my IDE is eclipse indigo and the jar spring-webmvc-3.1.0.RELEASE.jar which contains the DispatcherServlet exists in the lib
JavaBot
JavaBot3w ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
JavaBot
JavaBot3w ago
Post Closed
This post has been closed by <@1077604975741505716>.

Did you find this page helpful?