问题描述
限时送ChatGPT账号..我已尝试根据上述问题的答案进行搜索和更改,但没有奏效.我没有使用任何构建工具.
I have tried to search and make changes as per answers for above question, but not working. I am not using any build tool.
所有 jar 文件 jstl1.2、common loggings 1.1.3 和 Spring 3.2.3 jar 都在 WebContent/WEB-INF/lib 中
All the jar files jstl1.2, common loggings 1.1.3 , and Spring 3.2.3 jars are in WebContent/WEB-INF/lib
index.jsp 是欢迎文件在 Eclipse 浏览器中正确显示,但是当我单击控制器的超链接时,给出 404 请求的资源不可用.从日志看来 tomcat 没有加载调度程序 servlet
index.jsp is welcome file is shown properly in Eclipse browser, but when I click on hyperlink for controller, give 404 Requested resource not available. From the log seems tomcat is not loading dispatcher servlet
我尝试重新启动/清理并发布 tomcat,
I tried restarting/clean and publish tomcat,
使用 tomcat 7、jre7、eclipse keppler 4.0、java ee 2.0
using tomcat 7, jre7, eclipse kepller 4.0, with 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
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3/2001/XMLSchema-instance" xmlns="http://xmlns.jcp/xml/ns/javaee" xmlns:web="http://xmlns.jcp/xml/ns/javaee/web-app_3_1.xsd" xsi:schemaLocation="http://java.sun/xml/ns/javaee http://java.sun/xml/ns/javaee/web-app_3_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
spring-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework/schema/beans"
xmlns:xsi="http://www.w3/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework/schema/mvc"
xmlns:p="http://www.springframework/schema/p"
xmlns:context="http://www.springframework/schema/context"
xsi:schemaLocation="http://www.springframework/schema/mvc
http://www.springframework/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework/schema/beans
http://www.springframework/schema/beans/spring-beans-3.0.xsd
http://www.springframework/schema/context
http://www.springframework/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
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);
}
}
推荐答案
根据堆栈跟踪,您缺少包含 DispatcherServlet 类的 spring-webmvc.jar.再次尝试检查您的类路径 (WEB-INF/lib) 以确保 jar 存在.通常在 Spring MVC 应用程序中,您将需要这些 jars:
Based on the stack trace you are missing spring-webmvc.jar which contains DispatcherServlet class. Try check your classpath again (WEB-INF/lib) to make sure that jar is there. Typically on a Spring MVC application you'll need these jars:
我也建议你使用依赖管理工具(例如:Maven/ivy),否则你自己管理 jars 太难了
I also recommend you use dependency management tool (eg: Maven / ivy) otherwise it's too hard to manage the jars yourselves
这篇关于Tomcat 未加载 Dispatcher Servlet (ClassNotFoundException)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论