thoredge
thoredge

Reputation: 12661

RestEasy with Spring renders no answer

I can see that the FilterDispatcher is called (by debugger), but it doesn't seem to find the service to call. I've got trouble grasping how RestEasy actually maps between resources defined in Spring and RestEasy.

Main story: Getting http://my.local.no:8087/rest/typeaheads/h only renders 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 resource is set up by 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) {
        ...
    }
}

Upvotes: 0

Views: 443

Answers (1)

thoredge
thoredge

Reputation: 12661

The RestEasy SpringContextLoaderListener seem to be the missing part. I created a stripped down problem from RestEasy example and used it. For my somewhat more complex application however it would not work. That is probably because it overrides the deprecated createContextLoader-method. In Spring 3 ContextLoaderListener is an instance of ContextLoader. So I reimplemented it like this:

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

I originally tried to do the customizeContext(...) in a bean initialisation. That worked in RestEasy 2.2.1.GA, but not in 2.3.4.FINAL.

Upvotes: 2

Related Questions