RESTEasy Tutorial Part-2: Spring Integration

 

RESTEasy Tutorial Series

RESTEasy Tutorial Part-1: Basics

RESTEasy Tutorial Part-2: Spring Integration

RESTEasy Tutorial Part 3 – Exception Handling
RESTEasy provides support for Spring integration which enables us to expose Spring beans as RESTful WebServices.

Step#1: Configure RESTEasy+Spring dependencies using Maven.

Step#2: Configure RESTEasy+Spring in web.xml


		
   
    org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap
  
  
    org.jboss.resteasy.plugins.spring.SpringContextLoaderListener
  
  
    Resteasy
    org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher
  
  
    Resteasy
    /rest/*
  
  
    contextConfigLocation
    classpath:applicationContext.xml
  
  
    resteasy.servlet.mapping.prefix
    /rest
  

  
        resteasy.scan
        false
    

Step#3: Create a Spring Service class UserService and update UserResource to use UserService bean.

Step#4: Same JUnit TestCase to test the REST Webservice described in Part-1.

Important Things to Keep in mind:
1. org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap Listener should be registered before any other listener.
2. You should configure resteasy.servlet.mapping.prefix <context-param> if the HttpServletDispatcher servlet url-pattern is anything other than /*
3. While using Spring integration set resteasy.scan to false or don’t configure resteasy.scan parameter at all.
Otherwise you may get REST Resource instances(UserResource) from RestEasy instead of Spring container. While running JUnit Tests I observed this random behavior.

4. You should register REST Resource as Spring bean by annotating with @Component or @Service.

6 thoughts on “RESTEasy Tutorial Part-2: Spring Integration”

  1. Does anyone got a problem when trying to use propertyplaceholderconfigurer and ${something} into a bean's property but the configurer is instantiate only after the bean from some reason? Spring post processor??

  2. Hi Siva,
    This is works perfectly fine in Apache Tomcat 7.0.54 sever but when the same war file deployed in JBoss AS 7 ….deployment gets fail with error message "Caused by: java.lang.NoSuchMethodError: org.jboss.resteasy.spi.InjectorFactory.createPropertyInjector(Ljava/lang/Class;Lorg/jboss/resteasy/spi/ResteasyProviderFactory;)Lorg/jboss/resteasy/spi/PropertyInjector;"
    Any idea why behaviour .?? am using Spring-3.1.0.release and resteasy-3.0.8.Final
    TIA

Leave a Reply

Your email address will not be published. Required fields are marked *