运行简单弹簧应用程序时出错

时间:2011-12-24 14:46:47

标签: java spring java-ee spring-mvc

我正在按照本教程在我的系统中设置spring http://www.roseindia.net/spring/spring-mvc-hello-world.shtml

这是我的web.xml文件:

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

<web-app version="2.5"
    xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
    http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd" >
  <servlet>
    <servlet-name>dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>  
  <servlet-mapping>  
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>*.html</url-pattern>
  </servlet-mapping>  
  <welcome-file-list>  
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>

调度-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.InternalResourceViewResolver">
    <property name="prefix">
      <value>/WEB-INF/jsp/</value>
    </property>
    <property name="suffix">
     <value>.jsp</value>
    </property>
  </bean>
  <bean id="urlMapping"
      class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
    <property name="interceptors">
      <list>
        <ref local="localeChangeInterceptor"/>
      </list>
    </property>
    <property name="urlMap">
      <map>
        <entry key="/hello.html">
          <ref bean="helloController"/>
        </entry>
      </map>
    </property>
  </bean>
  <bean id="helloController" class="net.roseindia.web.HelloWorldController"> </bean>
  <bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
    <property name="paramName" value="hl"/>
  </bean>
  <bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver"/>
</beans>

我收到此错误:

HTTP Status 404 - Servlet dispatcher is not available

--------------------------------------------------------------------------------

type Status report

message Servlet dispatcher is not available

description The requested resource (Servlet dispatcher is not available) is not available.

可能是什么问题?我已经通过项目构建路径以及web-inf的lib文件夹添加了库。

2 个答案:

答案 0 :(得分:2)

将webapp的日志记录级别设置为DEBUG,并查看Spring在连接webapp并发送请求时生成的日志消息。这应该会给你一些关于出了什么问题的线索。

我还可以建议您使用官方的Spring手册,教程和示例。 Rose India上的东西看起来像是一个食谱,而不是一个适当的教程。它没有解释发生了什么。

答案 1 :(得分:0)

这应该是类路径问题。你能检查一下Spring-web jar是否在你创建的WAR中。它必须在web-inf lib中。如果你可以在那里找到它,打开它并检查所需的DispatcherServlet文件是否在其中。如果没有,您还没有正确添加依赖项。