Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resteasy and Spring integration without Spring ContextLoadListener

I am using Resteasy and Spring for my project. As Resteasy document said: http://docs.jboss.org/resteasy/docs/3.0.1.Final/userguide/html_single/index.html#RESTEasy_Spring_Integration.

I need to add a listener in the web.xml file:

<listener>
  <listener-class>org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class>

<listener>
  <listener-class>org.jboss.resteasy.plugins.spring.SpringContextLoaderListener</listener-class>

However, in my project we also used a cms called magnolia, and magnolia also has an implementation for SpringContextLoaderListener. If I put both context listener. The magnolia won't be started when I run the app.

So according to the Resteasy document said:

If you do not use a Spring ContextLoaderListener to create your bean factories, then you can manually register the RESTeasy BeanFactoryPostProcessor by allocating an instance of org.jboss.resteasy.plugins.spring.SpringBeanProcessor. You can obtain instances of a ResteasyProviderFactory and Registry from the ServletContext attributes org.jboss.resteasy.spi.ResteasyProviderFactory and org.jboss.resteasy.spi.Registry. (Really the string FQN of these classes). There is also a org.jboss.resteasy.plugins.spring.SpringBeanProcessorServletAware, that will automatically inject references to the Registry and ResteasyProviderFactory from the Servlet Context. (that is, if you have used RestasyBootstrap to bootstrap Resteasy).

Does anyone knows how can I achieve that without using Resteasy ContextLoaderListener? What do I need to put in my spring applicationContext xml file?

like image 834
ttt Avatar asked Oct 22 '22 05:10

ttt


1 Answers

I've also had problem with RestEasy SpringContextListener (properties placeholders ${...} weren't processed - RESTEASY-787, Spring java config didn't work etc.).
So it's enough to drop RestEasy SpringContextListener and use default org.springframework.web.context.ContextLoaderListener or whatever listener you need to. You just have to define Spring bean in your Spring XML configuration like this:

<bean class="org.jboss.resteasy.plugins.spring.SpringBeanProcessorServletAware"/>

Than RestEasy should work even without their special SpringContextListener. It works for me.

like image 84
Ondrej Bozek Avatar answered Oct 24 '22 04:10

Ondrej Bozek