Dieser Inhalt ist in der von Ihnen ausgewählten Sprache nicht verfügbar.

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.
Nach oben
Red Hat logoGithubredditYoutubeTwitter

Lernen

Testen, kaufen und verkaufen

Communitys

Über Red Hat Dokumentation

Wir helfen Red Hat Benutzern, mit unseren Produkten und Diensten innovativ zu sein und ihre Ziele zu erreichen – mit Inhalten, denen sie vertrauen können. Entdecken Sie unsere neuesten Updates.

Mehr Inklusion in Open Source

Red Hat hat sich verpflichtet, problematische Sprache in unserem Code, unserer Dokumentation und unseren Web-Eigenschaften zu ersetzen. Weitere Einzelheiten finden Sie in Red Hat Blog.

Über Red Hat

Wir liefern gehärtete Lösungen, die es Unternehmen leichter machen, plattform- und umgebungsübergreifend zu arbeiten, vom zentralen Rechenzentrum bis zum Netzwerkrand.

Theme

© 2025 Red Hat