此内容没有您所选择的语言版本。

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.
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat