0

Spring 4.0.2 で非常に単純なコントローラーを作成しようとしました。バージョン 3.1.2.RELEASE を使用すると問題なく動作します。ただし、maven の依存関係を 4.0.2.RELEASE にアップグレードすると、動作を停止します。

これが私の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>

ここに私の 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>

これが私のコントローラーです

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";
   }
}

これがWEB-INF/jspのhello.jspです

HELLO WORLD!

やってみると

http://localhost:8080/my-app/test.json 

エラー 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/ 「springDispatcher」という名前の DispatcherServlet 内の test.json]

何か見逃しましたか?Spring バージョン 3.1.2 では問題なく動作します。フィードバックは大歓迎です。

ありがとうございました

デビッド

4

2 に答える 2