Tomcat ไม่โหลด Dispatcher Servlet (ClassNotFoundException)

ฉันได้พยายามค้นหาและทำการเปลี่ยนแปลงตามคำตอบสำหรับคำถามข้างต้น แต่ไม่ได้ผล ฉันไม่ได้ใช้เครื่องมือสร้างใด ๆ

ไฟล์ jar ทั้งหมด jstl1.2, การบันทึกทั่วไป 1.1.3 และ Spring 3.2.3 jars อยู่ใน WebContent/WEB-INF/lib

index.jsp เป็นไฟล์ต้อนรับที่แสดงอย่างถูกต้องในเบราว์เซอร์ Eclipse แต่เมื่อฉันคลิกที่ไฮเปอร์ลิงก์สำหรับคอนโทรลเลอร์ แสดงว่าทรัพยากรที่ร้องขอ 404 ไม่พร้อมใช้งาน จากบันทึกดูเหมือนว่า Tomcat ไม่ได้โหลดเซิร์ฟเล็ตโปรแกรมเลือกจ่ายงาน

ฉันลองรีสตาร์ท / ทำความสะอาดและเผยแพร่ Tomcat

ใช้ tomcat 7, jre7, eclipse kepller 4.0, กับ java ee 2.0

ขอบคุณที่คุณช่วย

บันทึก Tomcat:

   ul 02, 2013 1:16:52 PM org.apache.catalina.core.ApplicationContext log
    I**NFO: No Spring WebApplicationInitializer types detected on classpath
    Jul 02, 2013 1:16:52 PM org.apache.catalina.core.ApplicationContext log
    INFO: Marking servlet spring as unavailable
    Jul 02, 2013 1:16:52 PM org.apache.catalina.core.StandardContext loadOnStartup
    SEVERE: Servlet /SpringMVC threw load() exception
    java.lang.ClassNotFoundException:             org.springframework.web.servlet.DispatcherServlet**
            
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1713)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1558)
    at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:527)
    at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:509)
    at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:137)
    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:5123)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5407)
    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)

Jul 02, 2013 1:16:53 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Jul 02, 2013 1:16:53 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Jul 02, 2013 1:16:53 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 11462 ms

เว็บ.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:web="http://xmlns.jcp.org/xml/ns/javaee/web-app
<?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:mvc="http://www.springframework.org/schema/mvc"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"

    xsi:schemaLocation="http://www.springframework.org/schema/mvc
                        http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
                        http://www.springframework.org/schema/beans
                        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                        http://www.springframework.org/schema/context
                        http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <context:component-scan
        base-package="com.maverick.springmvc.controller" />

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

</beans>
1.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app
<?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:mvc="http://www.springframework.org/schema/mvc"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"

    xsi:schemaLocation="http://www.springframework.org/schema/mvc
                        http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
                        http://www.springframework.org/schema/beans
                        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                        http://www.springframework.org/schema/context
                        http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <context:component-scan
        base-package="com.maverick.springmvc.controller" />

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

</beans>
0.xsd" id="WebApp_ID" version="3.0"> <display-name>SpringMVC</display-name>  <welcome-file-list>         <welcome-file>index.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>

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:mvc="http://www.springframework.org/schema/mvc"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"

    xsi:schemaLocation="http://www.springframework.org/schema/mvc
                        http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
                        http://www.springframework.org/schema/beans
                        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                        http://www.springframework.org/schema/context
                        http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <context:component-scan
        base-package="com.maverick.springmvc.controller" />

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

</beans>

HelloWorldController.java

package com.maverick.springmvc.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;


@Controller
public class HelloWorldController {


    @RequestMapping("/hello")
    public ModelAndView helloWorld() {

        System.out.println("test");
        String message = "Hello World, Spring 3.0!";
        return new ModelAndView("hello", "message", message);
    }
}

person user2477933    schedule 02.07.2013    source แหล่งที่มา
comment
ลองค้นหา DispatcherServlet ในเส้นทางการสร้างโดยใช้ ctrl+shift+T (ใน eclipse) และดูว่ามีขวดผลลัพธ์อยู่ในโครงการ lib ของคุณหรือไม่   -  person Laabidi Raissi    schedule 02.07.2013
comment
@LaabidiRaissi: สวัสดี อย่างที่คุณบอกว่ามันไม่แสดงในโปรเจ็กต์ lib ฉันได้แนบซอร์สมาแล้วแต่ใช้งานไม่ได้ เราจะแน่ใจได้อย่างไรว่าขวดทั้งหมดอยู่ในโปรเจ็กต์ lib ฉันคัดลอกขวดทั้งหมดในโฟลเดอร์ WebInf/lib แล้ว แค่นี้ไม่พอหรือเราต้องการอย่างอื่น? ขอบคุณสำหรับการชี้ให้เห็นสิ่งนี้   -  person user2477933    schedule 02.07.2013
comment
เราต้องการไฟล์ต้นฉบับหรือไม่? ฉันคิดว่าไฟล์ .class เท่านั้นก็เพียงพอแล้วใช่ไหม   -  person user2477933    schedule 02.07.2013
comment
คลิกขวาที่ขวดของคุณ --> สร้างเส้นทาง --> เพิ่มเพื่อสร้างเส้นทาง (ใน eclipse แน่นอน)   -  person Laabidi Raissi    schedule 02.07.2013
comment
แน่นอนว่าเราต้องการเพียง binary jars แต่เนื่องจากไม่พบคลาสบน classpath ของคุณ ดังนั้นจึงเพิ่มไม่ถูกต้อง   -  person Laabidi Raissi    schedule 02.07.2013


คำตอบ (2)


จากการติดตามสแต็ก คุณขาด spring-webmvc.jar ซึ่งมีคลาส DispatcherServlet ลองตรวจสอบ classpath ของคุณอีกครั้ง (WEB-INF/lib) เพื่อให้แน่ใจว่ามี jar อยู่ โดยทั่วไปแล้วในแอปพลิเคชัน Spring MVC คุณจะต้องมีขวดเหล่านี้:

ป้อนคำอธิบายรูปภาพที่นี่

ฉันขอแนะนำให้คุณใช้เครื่องมือการจัดการการพึ่งพา (เช่น Maven / ivy) ไม่เช่นนั้นจะยากเกินไปที่จะจัดการขวดด้วยตัวเอง

person gerrytan    schedule 02.07.2013
comment
ฉันมี jar ที่กล่าวถึงข้างต้นใน (WEB-INF/lib) แต่มันไม่ทำงาน ฉันได้เพิ่มมุมมอง explorer โปรเจ็กต์ eclipse ของฉันแล้ว แจ้งให้เราทราบหากคุณพบปัญหาใด ๆ เกี่ยวกับเรื่องนั้น - person user2477933; 02.07.2013
comment
มันไม่อนุญาตให้เพิ่มรูปภาพ แต่ฉันแน่ใจว่ามี jar อยู่ในไดเร็กทอรีที่คุณพูด - person user2477933; 02.07.2013
comment
ฉันพลาด commons-logging-1.1.1.jar ฉันเสียเวลาไปเกือบ 3 ชั่วโมง............ในที่สุดก็ได้ผล ขอบคุณ, - person Surajit Biswas; 24.03.2017

เพียงเพิ่มไฟล์ jar ที่จำเป็นทั้งหมดลงในโฟลเดอร์ WEB-INF/lib จากนั้นมันก็ใช้ได้สำหรับฉัน ในกรณีนี้เฉพาะคลาส DispatcherServlet ที่พบ

person Chandrasekhar Allu    schedule 05.12.2015