2013-04-04 46 views
0

我可以看到FilterDispatcher被調用(通過調試器),但它似乎沒有找到要調用的服務。我很難理解RestEasy如何在Spring和RestEasy中定義的資源之間進行映射。RestEasy with Spring呈現無答案

主要故事:讓http://my.local.no:8087/rest/typeaheads/h只呈現404

web.xml中

@Configuration 
@ComponentScan(basePackageClasses = TypeaheadsRestService.class) 
public class SpringConfig { 
} 

TypeaheadsRestService.java

... 
<context-param> 
    <param-name>resteasy.servlet.mapping.prefix</param-name> 
    <param-value>/rest</param-value> 
</context-param> 
<listener> 
    <listener-class>org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class> 
</listener> 
<listener> 
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
</listener> 
<filter> 
    <filter-name>restFilterDispatcher</filter-name> 
    <filter-class>org.jboss.resteasy.plugins.server.servlet.FilterDispatcher</filter-class> 
</filter> 
<filter-mapping> 
    <filter-name>restFilterDispatcher</filter-name> 
    <url-pattern>/rest/*</url-pattern> 
</filter-mapping> 
... 

RestEasy的資源是由豆設置:

@Resource 
@Path("/typeaheads") 
public class TypeaheadsRestService { 
    @GET 
    @Path("/{search}") 
    @Produces(MediaType.APPLICATION_JSON) 
    public List<NameUrl> get(@PathParam("search") String search) { 
     ... 
    } 
} 
+0

你可以分享客戶端代碼 – 2013-04-04 13:30:59

+0

該請求應該有一個頭'Accepts:application/json' – 2013-04-04 13:31:20

+0

試過頭部;但它沒有改變任何東西。 – thoredge 2013-04-04 13:50:46

回答

2

RestEasy SpringContextLoaderListener似乎是缺少的部分。我從RestEasy例子中創建了一個精簡的問題並使用它。但對於我的更復雜的應用程序來說,這是行不通的。這可能是因爲它會覆蓋已棄用的createContextLoader-方法。在春季3 ContextLoaderListenerContextLoader的一個實例。所以,我重新實現它是這樣的:

public class MyContextLoaderListener extends ContextLoaderListener { 
    private SpringContextLoaderSupport springContextLoaderSupport = new SpringContextLoaderSupport(); 
    @Override 
    protected void customizeContext(ServletContext servletContext, ConfigurableWebApplicationContext applicationContext) { 
     super.customizeContext(servletContext, applicationContext); 
     this.springContextLoaderSupport.customizeContext(servletContext, applicationContext); 
    } 
} 

我最初試圖做customizeContext(...)在一個bean的初始化。這在RestEasy 2.2.1.GA中起作用,但不在2.3.4.FINAL中。