我正在使用spring 4.0.4 RELEASE.jar,但是我没有找到类异常。
这是我的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"
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>SpringMvcApplication</display-name>
<servlet>
   <servlet-name>spring-dispatcher</servlet-name>
  <servlet-class>org.springframework.web.servlet.Dispatcherservlet</servlet-class>
 </servlet>
   <servlet-mapping>
 <servlet-name>spring-dispatcher</servlet-name>
   <url-pattern>/</url-pattern>
  </servlet-mapping>
</web-app>


这是我的spring-dispatcher-servlet.xml代码

<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:context="http://www.springframework.org/schema/context"
  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-4.0.xsd
  http://www.springframework.org/schema/context
  http://www.springframework.org/schema/context/spring-context-4.0.xsd">
 <context:component-scan base-package="com.javahash.spring.controller" />
       <bean id="HandlerMapping" name="/welcome.html"
  class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"       />
   <bean name="/welcome.html"
      class="com.manikant.hellocontroller.HelloController"/>
   <bean id= "viewResolver"

 class="org.springframework.web.servlet.view.InternalResourceViewResolver">
           <property name="prefix" value="/WEB-INF/" />
       <property name="suffix" value=".jsp" />
    </bean>
 </beans>


这是stacktrace:

javax.servlet.ServletException: Error instantiating servlet class org.springframework.web.servlet.Dispatcherservlet
            org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
            org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
            org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
            org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:522)
            org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1095)
            org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672)
            org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
            org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
            java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
            java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
            org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
            java.lang.Thread.run(Thread.java:745)

                java.lang.ClassNotFoundException:
        org.springframework.web.servlet.Dispatcherservlet
            org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1308)
            org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1142)
            org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
            org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
            org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
            org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:522)
            org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1095)
            org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672)
            org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
            org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
            java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
            java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
            org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
            java.lang.Thread.run(Thread.java:745)

最佳答案

注意错误消息:

Error instantiating servlet class org.springframework.web.servlet.Dispatcherservlet
                                                                            ^


然后在堆栈跟踪中:

java.lang.ClassNotFoundException: org.springframework.web.servlet.Dispatcherservlet


正确的拼写为DispatcherServlet,大写字母为S

关于java - 实例化servlet类org.springframework.web.servlet.DispatcherServlet时出错,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37904217/

10-08 23:16