Maverick
Maverick

Reputation: 2760

error with running simple spring application

I am following this tutorial to setup spring in my system, http://www.roseindia.net/spring/spring-mvc-hello-world.shtml.

Here is my web.xml file:

<?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>

dispatcher-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>

I am getting this error:

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.

What might be the problem? I have added the libraries through project build path and as well as in the lib folder of web-inf too.

Upvotes: 1

Views: 801

Answers (2)

Stephen C
Stephen C

Reputation: 718688

Set the webapp's logging level to DEBUG and look at the log messages produced by Spring as it wires up the webapp and dispatches the request. This should give you some clues as to what is going wrong.

Can I also suggest that you use the official Spring manuals, tutorials and examples. The stuff on Rose India looks like a recipe rather than a proper tutorial. It doesn't explain what is going on.

Upvotes: 2

Aravind A
Aravind A

Reputation: 9697

This should be a class path issue . Can you check if the Spring-web jar is inside the WAR you have created . It's got to be inside web-inf lib . If you can find it there, open it up and check if the required DispatcherServlet file is inside that . If not, you have not added the dependencies properly .

Upvotes: 0

Related Questions