I tried Spring MVC app as described in the book "Spring in Action 3rd Edition". Unfortunately, till now, I am not able to run the simplest app after wasting 6 hrs. I am always getting the "HTTP Status 404" error.
I found many threads on this forum for "@RequestMapping not working in Spring" and now wondering whether I am following the right book or is there something very basic which has troubled so many fellow Spring learners.
I tried running the MVC app in the book itself (Ch-7, spitter-web) but again, that app also didn't work. Looks like the author has not paid great attention in trying his own apps.
For the sake of completeness, my web.xml is:
<?xml version="1.0" encoding="UTF-8" ?>
<web-app 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_4.xsd"
version="2.4">
<context-param>
<description>locations of the Spring configuration files</description>
<param-name>contextConfigLocation</param-name>
<param-value>
</param-value>
</context-param>
<servlet>
<servlet-name>application</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>application</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>application</servlet-name>
<url-pattern>*.jsp</url-pattern>
</servlet-mapping>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
</web-app>
My application-servlet.xml is:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<!--<start id="spring_component_scan" />-->
<context:component-scan base-package="com.truality.demo.web.controller" />
<!--<end id="spring_component_scan" />-->
<!--<start id="mvc_annotatedcontrollers" />-->
<mvc:annotation-driven/>
<!--<end id="mvc_annotatedcontrollers" />-->
<context:annotation-config />
<!--<start id="mvc_resources"/>-->
<mvc:resources mapping="/resources/**" location="/resources/" />
<!--<end id="mvc_resources"/>-->
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/views/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
</beans>
And my Controller class is: package com.truality.demo.web.controller;
import java.util.Map;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class HomeController {
@RequestMapping(value={"/home.htm"}, method=RequestMethod.GET)
public String showHomePage(Map<String, String> model) {
model.put("name","Google");
return "home";
}
I am getting the 404 error always when I try accessing
- http://localhost:8080/demo-prop-1-1/home.htm OR
- http://localhost:8080/demo-prop-1-1/home.jsp
- http://localhost:8080/demo-prop-1-1/home
- http://localhost:8080/demo-prop-1-1
I am down to the point where I will start evaluating some other technology like PHP or ... if I could not solve this trivial issue.
Please help. Also, Can someone point me to good Spring book which give working examples so that some one can learn it fast?
Thanks a lot in advance.