有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

运行简单spring应用程序时出现java错误

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

这是我的网站。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.

有什么问题吗?我已经通过project build path和web inf的lib文件夹添加了这些库


共 (2) 个答案

  1. # 1 楼答案

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

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

  2. # 2 楼答案

    这应该是一个类路径问题。你能检查一下Spring web jar是否在你创建的战争中吗。它必须在web inf库中。如果你能在那里找到它,打开它,检查所需的DispatcherServlet文件是否在里面。如果没有,则说明您没有正确添加依赖项