Uploaded image for project: 'RESTEasy'
  1. RESTEasy
  2. RESTEASY-1012

Resteasy broken with Spring 4

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Major
    • 3.0.9.Final
    • 3.0.6.Final
    • None

    Description

      Spring 4
      Resteasy 3.0.6
      Tomcat 7

      I've recently upgraded to Spring 4 and am using the spring configuration with SpringContextLoaderListener.

      Spring 4 have removed the deprecated ContextLoaderListener#createContextLoader - so this method is never invoked. See ( http://docs.spring.io/spring/docs/3.0.x/api/org/springframework/web/context/ContextLoaderListener.html#getContextLoader() )

      Current workaround:

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

      Edit: 19.04.2014
      Seems like a couple of others are looking for a solution so will post a more complete solution/workaround..

      MyContextLoaderListener.java
      public class MyContextLoaderListener extends ContextLoaderListener {
      
      	private SpringContextLoaderSupport springContextLoaderSupport = new SpringContextLoaderSupport();
      
      	@Override
      	public void contextInitialized(ServletContextEvent event) {
      		boolean scanProviders = false;
      		boolean scanResources = false;
      
      		String sProviders = event.getServletContext().getInitParameter(
      				"resteasy.scan.providers");
      		if (sProviders != null) {
      			scanProviders = Boolean.valueOf(sProviders.trim());
      		}
      		String scanAll = event.getServletContext().getInitParameter(
      				"resteasy.scan");
      		if (scanAll != null) {
      			boolean tmp = Boolean.valueOf(scanAll.trim());
      			scanProviders = tmp || scanProviders;
      			scanResources = tmp || scanResources;
      		}
      		String sResources = event.getServletContext().getInitParameter(
      				"resteasy.scan.resources");
      		if (sResources != null) {
      			scanResources = Boolean.valueOf(sResources.trim());
      		}
      
      		if (scanProviders || scanResources) {
      			throw new RuntimeException(
      					"You cannot use resteasy.scan, resteasy.scan.resources, or resteasy.scan.providers with the SpringContextLoaderLister as this may cause serious deployment errors in your application");
      		}
      
      		super.contextInitialized(event);
      	}	
      	@Override
      	protected void customizeContext(ServletContext servletContext, ConfigurableWebApplicationContext configurableWebApplicationContext) {
      		
      		super.customizeContext(servletContext, configurableWebApplicationContext);		
      		this.springContextLoaderSupport.customizeContext(servletContext, configurableWebApplicationContext);
      	}
      }
      
      web.xml
      <listener>
      	<listener-class&gt;org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class&gt;
      </listener> 
      <!-- listener>
      	<listener-class&gt;org.resteasy.plugins.spring.SpringContextLoaderListener</listener-class&gt;
      </listener -->   
      <listener>	
      	<listener-class&gt;yourpackage.spring.MyContextLoaderListener</listener-class&gt;
      </listener>
      

      Attachments

        Activity

          People

            patriot1burke@gmail.com Bill Burke (Inactive)
            magnus.kvalheim Bård Magnus Kvalheim (Inactive)
            Votes:
            12 Vote for this issue
            Watchers:
            13 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: