Este contenido no está disponible en el idioma seleccionado.

Chapter 35. Spring Integration


RESTEasy integrates with Spring 2.5. (We are interested in other forms of Spring integration, and encourage you to contribute.)

35.1. Basic Integration

For Maven users, you must use the resteasy-spring artifact. Otherwise, the jar is available in the downloaded distribution.
<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-spring</artifactId>
    <version>whatever version you are using</version>
</dependency>
Copy to Clipboard Toggle word wrap
RESTEasy includes its own Spring ContextLoaderListener. This registers a RESTEasy-specific BeanPostProcessor that processes JAX-RS annotations when a bean is created by a BeanFactory. This means that RESTEasy automatically scans for @Provider and JAX-RS resource annotations on your bean class and registers them as JAX-RS resources.
You will need to alter your web.xml file:
<web-app>
   <display-name>Archetype Created Web Application</display-name>

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

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

   <servlet>
      <servlet-name>Resteasy</servlet-name>
      <servlet-class>org.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
   </servlet>

   <servlet-mapping>
      <servlet-name>Resteasy</servlet-name>
      <url-pattern>/*</url-pattern>
   </servlet-mapping>


</web-app>
Copy to Clipboard Toggle word wrap
The SpringContextLoaderListener must be declared after ResteasyBootstrap because it uses ServletContext attributes initialized by ResteasyBootstrap.
If you do not use a Spring ContextLoaderListener to create your bean factories, 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 attribute, org.resteasy.spi.ResteasyProviderFactory and org.resteasy.spi.Registry (the fully-qualified name String of these classes). There is also org.jboss.resteasy.plugins.spring.SpringBeanProcessorServletAware, which automatically injects references to the Registry and ResteasyProviderFactory from the Servlet Context, assuming that you have used RestasyBootstrap to bootstrap RESTEasy.
RESTEasy Spring integration supports both singletons and the prototype scope. It handles injecting @Context references. However, constructor injection is not supported, and when the prototype scope is used, RESTEasy injects any @*Param-annotated fields and setters before the request is dispatched.

Note

You can only use automatically proxied beans with RESTEasy Spring integration. Hand-coded proxying (that is, with ProxyFactoryBean) will have undesirable effects.
Volver arriba
Red Hat logoGithubredditYoutubeTwitter

Aprender

Pruebe, compre y venda

Comunidades

Acerca de la documentación de Red Hat

Ayudamos a los usuarios de Red Hat a innovar y alcanzar sus objetivos con nuestros productos y servicios con contenido en el que pueden confiar. Explore nuestras recientes actualizaciones.

Hacer que el código abierto sea más inclusivo

Red Hat se compromete a reemplazar el lenguaje problemático en nuestro código, documentación y propiedades web. Para más detalles, consulte el Blog de Red Hat.

Acerca de Red Hat

Ofrecemos soluciones reforzadas que facilitan a las empresas trabajar en plataformas y entornos, desde el centro de datos central hasta el perímetro de la red.

Theme

© 2025 Red Hat