Announcement Announcement Module
No announcement yet.
Resteasy in Spring 3.1 (Servlet 3) - Zero Conf Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Resteasy in Spring 3.1 (Servlet 3) - Zero Conf

    Hi everybody,
    it is so frustrating so I hope you are able to help me with my current problem.

    I have got the following technology stack:

    - Spring 3.1
    - Servlet 3 environment
    - Resteasy

    I want to raise up a Resteasy Rest API as a second Servlet. The beans are configured in my root context. In our project we are not using the web.xml nor any xml-configuration but
    configuring everything via a WebApplicationInitializer (Servlet 3).

    The problem is, that the usual way is to use the XML approach, where the SpringContextLoaderListener does not extend the new Constructor, which takes the root context.

    I tried to use the following approach:

    public abstract class AbstractWebAppInitializer implements WebApplicationInitializer {
    	public void onStartup(ServletContext servletContext) throws ServletException {
    		servletContext.addListener(new ResteasyBootstrap());
    		servletContext.addListener(new ContextLoaderListener(getRootContext()));
    	private void initResteasy(ServletContext servletContext) {
    		ResteasyProviderFactory providerFactory = (ResteasyProviderFactory) servletContext.getAttribute(ResteasyProviderFactory.class.getName());
    		if (providerFactory == null) throw new RuntimeException(
    				"RESTeasy Provider Factory is null, do you have the ResteasyBootstrap listener configured?");
    		Registry registry = (Registry) servletContext.getAttribute(Registry.class.getName());
    		if (registry == null) throw new RuntimeException(
    				"RESTeasy Registry is null, do ou have the ResteasyBootstrap listener configured?");
    		Dispatcher dispatcher = (Dispatcher) servletContext.getAttribute(Dispatcher.class.getName());
    		if (dispatcher == null) throw new RuntimeException(
    				"RESTeasy Dispatcher is null, do ou have the ResteasyBootstrap listener configured?");
    		SpringBeanProcessor processor = new SpringBeanProcessor(dispatcher, registry, providerFactory);
    What basically happens is, that in the first step the Resteasy beans are registered in the servletContext, and later they should be used as BeanPostProcessors, I guess that the Postprocessor is searching
    for jax-rs annotated beans, so they can be exposed via Resteasy.

    But my solution is not working, as to the time of the initResteasy() call, the beans are not registered already.

    There there anybody, who was able to use Resteasy in such a Servlet3 configuration already?

    Thanks so much in advance.

    P.S. The reason for my approach is, that I tried to switch from Jersey to Resteasy, as Jesey made a lot of trouble with different versions etc. And I do not want to use Springs default Rest implementation, as jax-rs is pretty straight forward.

  • #2
    i use spring 3.2 with spring-resteasy which comes with its spring-mvc config,
    so basically all to set up is in your web.xml
    did you setup the resteasy dispatcher or
    had a look at this spring-mvc config if you are programmatically wiring this up ?