2014-12-12 2 views
0

그래서 나는 보이는 봄 REST 애플리케이션을 쓴이 같은 비트 :필터가 호출되지 않습니다.

의 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_3_0.xsd" id="WebApp_ID" version="3.0"> <display-name>Archetype Created Web Application</display-name> 

<filter> 
    <filter-name>CORSFilter</filter-name> 
    <filter-class>com.billboard.filters.SimpleCORSFilter</filter-class> 
    </filter> 
    <filter-mapping> 
    <filter-name>CORSFilter</filter-name> 
    <url-pattern>/</url-pattern> 
    </filter-mapping> 

    <servlet> 
     <servlet-name>mvc-dispatcher</servlet-name> 
     <servlet-class> 
      org.springframework.web.servlet.DispatcherServlet 
     </servlet-class> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 
    <servlet-mapping> 
     <servlet-name>mvc-dispatcher</servlet-name> 
     <url-pattern>/</url-pattern> 
    </servlet-mapping> 

</web-app> 

MVC-디스패처-servlet.xml에 :

<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:mvc="http://www.springframework.org/schema/mvc" 
    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-3.0.xsd 
     http://www.springframework.org/schema/context 
     http://www.springframework.org/schema/context/spring-context-3.0.xsd 
     http://www.springframework.org/schema/mvc 
     http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"> 

    <context:component-scan base-package="com.billboard.imageService"/> 

    <mvc:annotation-driven/> 

</beans> 

및 컨트롤러 다음과 같습니다 : package com.billboard.imageService;

import java.util.List; 

import org.springframework.stereotype.Controller; 
import org.springframework.web.bind.annotation.PathVariable; 
import org.springframework.web.bind.annotation.RequestBody; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.RequestMethod; 
import org.springframework.web.bind.annotation.ResponseBody; 

import com.billboard.rangeCache.Cache; 
import com.billboard.rangeCache.CacheManager; 
import com.billboard.rangeCache.ICache; 

@Controller 
public class ImageController { 

    @RequestMapping("/get") 
    public @ResponseBody String test() { 
     System.out.println("get images"); 
     return "okay"; 
    } 

    @RequestMapping("/getImages/{start}/{size}") 
    public @ResponseBody List<Image> getImages(@PathVariable String start, @PathVariable String size) { 
     System.out.println("get images"); 
     ICache<Image> cache = CacheManager.getCache("imageCache"); 
     return cache.get(Integer.parseInt(start), Integer.parseInt(size)); 
    } 
} 

문제는 필터가 호출되지 않습니다. 내가 여기서 뭔가 잘못하고있는거야? Spring MVC는 컨테이너가 필터를 처리하는 방식을 방해합니까? (나는 그것을 매우 의심한다). 내가하려는 것은 REST 서비스가 COR ​​(Cross origin requests)을 구현하는지 확인하는 것이다.

답변

1

당신은 당신의 URL 매핑에 *을 추가 할 수 있습니다 :

<filter-mapping> 
    <filter-name>CORSFilter</filter-name> 
    <url-pattern>/*</url-pattern> 
</filter-mapping> 

를 내가는 "루트"아무것도 다른 서비스를 제공합니다 생각합니다.

모든 요청을 웹 응용 프로그램에 기록하려면 적중 카운터 필터를/* 패턴으로 매핑해야합니다.

Here is a link to filters 위 인용 부호는에서 인용 한 것입니다.

관련 문제