Announcement Announcement Module
Collapse
No announcement yet.
java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet

    Hello,

    I am trying to use spring MVC using spring 2.5 and I am getting a java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet exception.

    I can see from other posts that this class should be in spring.jar but I can't see it. Can someone tell me if it has been moved - or perhaps lend me a pair of glasses?

    FYI spring.jar is being deployed correctly in tomcat.

    Thanks.

  • #2
    Originally posted by Don Jonson View Post
    Hello,

    I am trying to use spring MVC using spring 2.5 and I am getting a java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet exception.

    I can see from other posts that this class should be in spring.jar but I can't see it. Can someone tell me if it has been moved - or perhaps lend me a pair of glasses?

    FYI spring.jar is being deployed correctly in tomcat.

    Thanks.
    You may need to add the spring-webmvc.jar to your classpath too. They no more have everything in spring.jar.. You might have to add more jars in your classpath after 2.5.

    Comment


    • #3
      Thanks. I figured it out in the end. I also had to add:

      spring-beans - 2.5.2
      spring-webmvc - 2.5.2
      spring-webflow - 1.0.5
      spring - 2.5.2

      Comment


      • #4
        Adding spring-webmvc should be enough!

        spring-beans content is also in the spring.jar.
        spring-webflow you only need if you also use/intend to use Spring Web Flow, if you didn't need it before then you shouldn't need it now....

        Comment


        • #5
          Nullpointer in DispatcherServlet

          I have added all the jars and am able to import the org.springframework.web.servlet.DispatcherServlet package into my java file, but still am getting Null Pointer exception in Console and getting following error in page:
          org.springframework.beans.factory.BeanDefinitionSt oreException: Line 5 in XML document from ServletContext resource [/WEB-INF/dispatcher-servlet.xml] is invalid; nested exception is org.xml.sax.SAXParseException: Document root element "beans", must match DOCTYPE root "null".

          timely help would be appreciated.

          by
          Ranjith

          Comment


          • #6
            It would help if you could post the xml.

            Comment


            • #7
              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_2_5.xsd" id="WebApp_ID" version="2.5">
              <display-name>SpringExample6</display-name>
              <servlet>
              <servlet-name>dispatcher</servlet-name>
              <servlet-class>org.springframework.web.servlet.DispatcherSe rvlet</servlet-class>
              <load-on-startup>1</load-on-startup>
              </servlet>
              <servlet-mapping>
              <servlet-name>dispatcher</servlet-name>
              <url-pattern>*.htm</url-pattern>
              </servlet-mapping>
              <welcome-file-list>
              <welcome-file>redirect.jsp</welcome-file>
              </welcome-file-list>
              </web-app>

              dispatcher-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"
              xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

              <bean id="viewResolver"
              class="org.springframework.web.servlet.view.Intern alResourceViewResolver" >
              <property name="prefix">
              <value>/WEB-INF/jsp/</value>
              </property>
              <property name="suffix">
              <value>.jsp</value>
              </property>
              </bean>

              <bean name="/welcome.htm" class="com.vaannila.HelloWorldController" >
              <property name="message" value="Hello World!" />
              </bean>

              </beans>

              These are the xml which i have included in WEB-INF Folder. I am able to import org.springframework.web.servlet.DispatcherServlet class in my java classs which means that the jar which i hv included contains this class.
              can anyone help on this.?
              Thanks in advance
              Ranjith

              Comment


              • #8
                Ranjith, If the class compiles, it does not mean it will work at runtime unless you have the required jars in the classpath while running the application. One sure shot way of making sure that the required spring jars are in the classpath at runtime would be to put them in /WEB-INF/lib folder.

                Hope this helps.

                Comment


                • #9
                  Thanks lot. it works nw..

                  Comment


                  • #10
                    java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet

                    Hi everyone...if you are running the hello world example from http://www.vaannila.com/spring/sprin...l-1.html..than please follow the following things strictly:

                    1) Directory structure of the example should exactly be the same.

                    2) In the WEB-INF/lib folder-->> put all the spring 3.0.0 jar files.

                    3) You can download them from :

                    http://www.docjar.com/jar_detail/org....0.M3.jar.html

                    4) These will be downloaded as zip file. Just drag and drop to lib folder and reaname to .jar and add to the build path.

                    5) Clean the project and republish,start the server and run the redirect.jsp on server.

                    You now must be able to say 'hello' to the Spring world .

                    N.B. Clean the project and restart the eclipse if required(In the Eclipse menu-->>File--->>Restart).

                    I had a chain of issues as I was using Spring 3.0.3 and the issue was not getting resolved I mixed up 2.5.0 and other versions of jar.
                    This only complicated the simple program and I got 404,500, java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet
                    and beansbindingexception and errorfield exception..and on and on...

                    Now it works for me






                    Originally posted by ranjiths View Post
                    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_2_5.xsd" id="WebApp_ID" version="2.5">
                    <display-name>SpringExample6</display-name>
                    <servlet>
                    <servlet-name>dispatcher</servlet-name>
                    <servlet-class>org.springframework.web.servlet.DispatcherSe rvlet</servlet-class>
                    <load-on-startup>1</load-on-startup>
                    </servlet>
                    <servlet-mapping>
                    <servlet-name>dispatcher</servlet-name>
                    <url-pattern>*.htm</url-pattern>
                    </servlet-mapping>
                    <welcome-file-list>
                    <welcome-file>redirect.jsp</welcome-file>
                    </welcome-file-list>
                    </web-app>

                    dispatcher-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"
                    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

                    <bean id="viewResolver"
                    class="org.springframework.web.servlet.view.Intern alResourceViewResolver" >
                    <property name="prefix">
                    <value>/WEB-INF/jsp/</value>
                    </property>
                    <property name="suffix">
                    <value>.jsp</value>
                    </property>
                    </bean>

                    <bean name="/welcome.htm" class="com.vaannila.HelloWorldController" >
                    <property name="message" value="Hello World!" />
                    </bean>

                    </beans>

                    These are the xml which i have included in WEB-INF Folder. I am able to import org.springframework.web.servlet.DispatcherServlet class in my java classs which means that the jar which i hv included contains this class.
                    can anyone help on this.?
                    Thanks in advance
                    Ranjith

                    Comment


                    • #11
                      <dependency>
                      <groupId>org.springframework</groupId>
                      <artifactId>spring-webmvc</artifactId>
                      <version>3.0.5.RELEASE</version>
                      </dependency>



                      Enter to your pom file

                      Comment

                      Working...
                      X