I have tried to create a very simple controller with Spring 4.0.2. It works fine if I used version 3.1.2.RELEASE. However, once I upgraded the maven dependency to 4.0.2.RELEASE. It stop working.
Here is my web.xml
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>my-app</display-name>
<servlet>
<servlet-name>springDispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springDispatcher</servlet-name>
<url-pattern>*.json</url-pattern>
</servlet-mapping>
</web-app>
Here is my springDispatcher-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"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
<context:component-scan base-package="com.tsun.sample"/>
<bean
class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"
/>
<bean
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"
/>
</beans>
Here is my controller
package com.tsun.sample;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
@Controller
public class TestController {
@RequestMapping(value="/test.json", method=RequestMethod.GET)
public String simpleMethod(ModelMap model) {
return "hello";
}
}
Here is my hello.jsp in WEB-INF/jsp
HELLO WORLD!
When I try
http://localhost:8080/my-app/test.json
There is error 2014-03-14 14:38:34,417 WARN [org.springframework.web.servlet.PageNotFound] (http-0.0.0.0-8080-1) No mapping found for HTTP request with URI [/my-app/test.json] in DispatcherServlet with name 'springDispatcher'
Did I miss anything? It works fine for Spring version 3.1.2 Any feedback is welcome!
Thank you
David