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

      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>
      

            [RESTEASY-1012] Resteasy broken with Spring 4

            Thanks Bard for your workaround, good stuff!
            Meanwhile I still can't get 3.0.10 to work properly (hibernate validation stopped working) so had to downgrade to 3.0.6 which works well using your workaround.

            Jacek Obarymski (Inactive) added a comment - Thanks Bard for your workaround, good stuff! Meanwhile I still can't get 3.0.10 to work properly (hibernate validation stopped working) so had to downgrade to 3.0.6 which works well using your workaround.

            Thanks jett_jira! Looks like the Rest easy probably added the hacked listener. Thanks again.

            Rahul A (Inactive) added a comment - Thanks jett_jira ! Looks like the Rest easy probably added the hacked listener. Thanks again.

            rahulaga_jira 3.0.9.Final works with Spring 4 as indicated. Please https://github.com/incuventure/training-fullstack. I built it using Spring 4.1.0, and RESTEasy 3.0.9.

            There's a little bit more than RESTEasy but you should be able to see the relevant config entries.

            Jett Gamboa (Inactive) added a comment - rahulaga_jira 3.0.9.Final works with Spring 4 as indicated. Please https://github.com/incuventure/training-fullstack . I built it using Spring 4.1.0, and RESTEasy 3.0.9. There's a little bit more than RESTEasy but you should be able to see the relevant config entries.

            True. Is Rest Easy not going to support Spring 4?

            Rahul A (Inactive) added a comment - True. Is Rest Easy not going to support Spring 4?

            rahulaga_jira To be fair, the documenation refers to Spring 3.x whereas this issue relates to Spring 4.x:

            RESTEasy integrates with Spring 3.0.x...

            Donovan Muller (Inactive) added a comment - rahulaga_jira To be fair, the documenation refers to Spring 3.x whereas this issue relates to Spring 4.x: RESTEasy integrates with Spring 3.0.x...

            This should not be marked fixed.
            As documented the feature is still broken: http://docs.jboss.org/resteasy/docs/3.0.9.Final/userguide/html_single/#RESTEasy_Spring_Integration

            Rahul A (Inactive) added a comment - This should not be marked fixed. As documented the feature is still broken: http://docs.jboss.org/resteasy/docs/3.0.9.Final/userguide/html_single/#RESTEasy_Spring_Integration

            Not completely satisified with the above solution I found that the resource handler set by WebMvcAutoConfiguration might be the gaining priority over Resteasy.
            So by changing the order of the resteasy handlermapping - the boot auto configuration works with resteasy in my experience.

            ResteasyConfig.java
            @Configuration
            //@EnableWebMvc /*No need to disable WebMvcAutoConfiguration as we set the ordering in springboot-resteasy-patch.xml*/
            @ImportResource({"classpath:springboot-resteasy-patch.xml"})
            public class ResteasyConfig {
            }
            
            springboot-resteasy-patch.xml
            <?xml version="1.0" encoding="UTF-8"?>
            <beans xmlns="http://www.springframework.org/schema/beans"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xmlns:p="http://www.springframework.org/schema/p"
                xmlns:context="http://www.springframework.org/schema/context"
                xsi:schemaLocation="
                    http://www.springframework.org/schema/beans
                    http://www.springframework.org/schema/beans/spring-beans.xsd
                    http://www.springframework.org/schema/context
                    http://www.springframework.org/schema/context/spring-context.xsd">
                   
                <import resource="classpath:springmvc-resteasy.xml"/>
                
            	<bean id="resteasy.handlerMapping" parent="abstract.resteasy.handlerMapping">
            		<property name="order" value="0"/>
            	</bean>
            </beans>
            

            Bård Magnus Kvalheim (Inactive) added a comment - Not completely satisified with the above solution I found that the resource handler set by WebMvcAutoConfiguration might be the gaining priority over Resteasy. So by changing the order of the resteasy handlermapping - the boot auto configuration works with resteasy in my experience. ResteasyConfig.java @Configuration //@EnableWebMvc /*No need to disable WebMvcAutoConfiguration as we set the ordering in springboot-resteasy-patch.xml*/ @ImportResource({ "classpath:springboot-resteasy-patch.xml" }) public class ResteasyConfig { } springboot-resteasy-patch.xml <?xml version= "1.0" encoding= "UTF-8" ?> <beans xmlns= "http: //www.springframework.org/schema/beans" xmlns:xsi= "http: //www.w3.org/2001/XMLSchema-instance" xmlns:p= "http: //www.springframework.org/schema/p" xmlns:context= "http: //www.springframework.org/schema/context" xsi:schemaLocation=" http: //www.springframework.org/schema/beans http: //www.springframework.org/schema/beans/spring-beans.xsd http: //www.springframework.org/schema/context http: //www.springframework.org/schema/context/spring-context.xsd"> < import resource= "classpath:springmvc-resteasy.xml" /> <bean id= "resteasy.handlerMapping" parent= " abstract .resteasy.handlerMapping" > <property name= "order" value= "0" /> </bean> </beans>

            jett_jira I have just tried Resteasy with spring boot and the approach suggested above by mdoninger works well.

            Like so:

            ResteasyConfig.java
            @Configuration
            @EnableWebMvc
            @ImportResource({"classpath:springmvc-resteasy.xml"})
            public class ResteasyConfig {
            
            }
            

            Bård Magnus Kvalheim (Inactive) added a comment - jett_jira I have just tried Resteasy with spring boot and the approach suggested above by mdoninger works well. Like so: ResteasyConfig.java @Configuration @EnableWebMvc @ImportResource({ "classpath:springmvc-resteasy.xml" }) public class ResteasyConfig { }

            Glad to see that the bug is fixed. Are there any examples of this working with Spring Boot?

            Jett Gamboa (Inactive) added a comment - Glad to see that the bug is fixed. Are there any examples of this working with Spring Boot?

            looks like this has been fixed.

            Bill Burke (Inactive) added a comment - looks like this has been fixed.

              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

                Created:
                Updated:
                Resolved: