此内容没有您所选择的语言版本。
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.
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:
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.