RestEasy with Spring无法回答

时间:2013-04-04 13:21:20

标签: spring resteasy

我可以看到FilterDispatcher被调用(通过调试器),但它似乎找不到要调用的服务。我很难理解RestEasy如何实际映射Spring和RestEasy中定义的资源。

主要故事:获取http://my.local.no:8087/rest/typeaheads/h仅呈现404

的web.xml

...
<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资源由bean设置:

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

TypeaheadsRestService.java

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

1 个答案:

答案 0 :(得分:2)

RestEasy SpringContextLoaderListener 似乎是缺失的部分。我从RestEasy示例创建了一个精简问题并使用它。对于我更复杂的应用程序,它不起作用。这可能是因为它会覆盖已弃用的 createContextLoader -method。在Spring 3中, ContextLoaderListener ContextLoader 的一个实例。所以我重新实现了它:

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

我最初尝试在bean初始化中执行 customizeContext(...)。这在RestEasy 2.2.1.GA中有效,但在2.3.4.FINAL中没有。