0

So I am learning Spring MVC and have this error java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet

I think I kinda know the error. It has something to do with mapping but my poor knowledge with mapping cannot solve the problem. So here are the classes...I do not think I am missing external JAR though. I attached every necessary jar files.

Ok I do not know how to insert image from my computer here so. Here is my index.jsp page.

Home Login

When the user clicks "login" tab, the dispatcher-servlet will call the controller below and take the clicker to UserLogin.jsp page

Here is the error code:

java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1702)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1547)
    at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:532)
    at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:514)
    at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:142)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1144)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1088)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5176)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5460)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
    at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

package com.fdmgroup.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

    @Controller
    public class LoginController {

        /* Loading Home Page */
        @RequestMapping(value = "/Login.html", method = RequestMethod.GET)
        public String loadIndexPage() {
            return "UserLogin";
        }


    }

This is my web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>LibraryHybernateSpringMaven</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>

    <servlet>
        <servlet-name>spring</servlet-name>
        <servlet-class>
            org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>spring</servlet-name>
        <url-pattern>*.html</url-pattern>
    </servlet-mapping>

</web-app>

This is my spring-servlet.xml

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

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jee="http://www.springframework.org/schema/jee"
    xmlns:lang="http://www.springframework.org/schema/lang"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:util="http://www.springframework.org/schema/util"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
        http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">

   <!-- Scan the package containing annotations -->     
  <context:annotation-config />
  <context:component-scan base-package="com.fdmgroup.daoimpl, com.fdmgroup.servicelayers" />

  <!-- jspViewResolver bean – This bean defined view resolver for spring mvc. For this bean we also set prefix as “/WEB-INF/jsp/”
   and suffix as “.jsp”. Thus spring automatically resolves the JSP from WEB-INF/jsp folder and assigned suffix .jsp to it. -->
  <bean id="jspViewResolver"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="viewClass"
            value="org.springframework.web.servlet.view.JstlView" />
        <property name="prefix" value="/WEB-INF/jsp/" />
        <property name="suffix" value=".jsp" />
    </bean>

 </beans>

This my pom.xml

<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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>LibraryHybernateSpringMaven</groupId>
  <artifactId>LibraryHybernateSpringMaven</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.1</version>
        <configuration>
          <source>1.7</source>
          <target>1.7</target>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <dependencies>
    <dependency>
        <groupId>springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>1.2.6</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
        <version>3.2.5.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>3.2.5.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context-support</artifactId>
        <version>3.2.5.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>com.github.ferstl</groupId>
        <artifactId>spring-jdbc-oracle-ojdbc</artifactId>
        <version>0.9.0</version>
    </dependency>
    <dependency>
        <groupId>com.mysema.spring</groupId>
        <artifactId>spring-tx-annotations</artifactId>
        <version>0.1.0</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>3.2.5.RELEASE</version>
    </dependency>
  </dependencies>
</project>

Are there any books that explain how to program using Spring MVC like the book Java How to Program? Thank you

4
  • Spring core 1.2.6? Yes, there are books, tutorials, sample apps, etc. Commented Dec 1, 2013 at 2:28
  • Post the complete exception. Commented Dec 1, 2013 at 2:30
  • So what was your specific problem? Your main question, as it is, is asking for recommendations - which is frowned upon. If you could isolate the specific error with your code, we'd be more able to help you out. Commented Dec 1, 2013 at 2:30
  • I edited my question with error logs. Class Not found:Dispatcher Servlet. I think because of that when I click the "login" tab I get to the page with 404 error and no resource found. Commented Dec 1, 2013 at 2:34

4 Answers 4

1

Seems everything right, as this topic:

Can't run 'Hello World" Spring MVC code

You can search the differences between your project and the template i shared there or just use it.

Sign up to request clarification or add additional context in comments.

Comments

0

You can follow below link .

http://www.mkyong.com/spring3/spring-3-mvc-hello-world-example/ step wise explanation .Looks likes you have missing some core dependencies of spring MVC in your class path

1 Comment

I still can't find it. I copy Mkyong example and still having class not found error. Now I have tag library error for "uri="java.sun.com/jsp/jstl/core" ". I did not even touch that file.
0

Everything looks okay. Looks like the dependencies are missing from the build path.

Make sure that you have the maven dependency in your Java Build Path and Deployment Assembly.

Edit 1:

Try to do the following:

a) To check if you have the dependencies in your build path. Right click on the project and goto --> Java Build Path see if you have Maven Dependency catalog in the build path. If you don't have it click on Add Lib and select Java Build Path Entries and then, Maven Dependency. Though not really required but similarly, go to the deployment assembly and see if you have the Maven Dependency there.

b) Try by changing the version of the spring-core dependency to 3.2.5.RELEASE

2 Comments

So this is how I have to add those JAR files right. Right click project, build path, add external jars. I have seen posts saying those Spring JARS need to be insude /web-inf/lib
Updated my answer take a look!
0

I figured out why it cannot find the DispatcherServlet. I have to add the dependencies into Deployment Assembly. Here is the step for beginners like me who come across the similiar situation:

Right click project Build path Deployment Assembly > click on web content > click add Click Java Build Path entries > then add the libraries and dependencies

1 Comment

Raunak Agarwal answered it. Omg I should have looked at his updated answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.