java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet in spring project Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet in spring project without wasting too much if your time.

The question is published on by Tutorial Guruji team.

one hello.jsp

web.xml is

<?xml version="1.0" encoding="UTF-8"?>

http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd” version=”3.0″>

<welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>

<!-- The front controller of this Spring Web application, responsible for 
    handling all application requests -->
<servlet>
    <servlet-name>dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>

</servlet>

<!-- Map all requests to the DispatcherServlet for handling -->
<servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>*.html</url-pattern>
</servlet-mapping>

dispatcher-servlet.xml is

<?xml version="1.0" encoding="UTF-8"?>

http://www.springframework.org/schema/beans/spring-beans-2.5.xsd”

xmlns:p="http://www.springframework.org/schema/p">

<bean id="viewResolver"

    class="org.springframework.web.servlet.view.InternalResourceViewResolver">

    <property name="prefix">

        <value>/WEB-INF/jsp/</value>

    </property>

    <property name="suffix">

        <value>.jsp</value>

    </property>

</bean>
<bean name="/hello.html" class="com.spring.HelloWorldController"></bean>
</beans>

JAR Files are: spring.jar spring-webmvc.jar spring-aop spring-beans spring-context spring-context-support spring-core spring-jdbc spring-orm spring-source spring-test spring-tx

Answer

The ClassNotFoundException clearly indicates that you are missing org.springframework.web.servlet classes.

If you are not using Maven, make sure you include all the appropriate Spring JARs.

If you are using Maven, make sure you include the spring-web dependency:

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version><!-- Your spring version here --></version>
    </dependency>

If none of these work, take a look at this thread.

We are here to answer your question about java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet in spring project - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji