RESTEasy integrates with Spring 3.0.x. We are interested in other forms of Spring integration, so please help contribute.
41.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>
RESTeasy comes with its own Spring ContextLoaderListener that registers a RESTeasy specific BeanPostProcessor that processes JAX-RS annotations when a bean is created by a BeanFactory. What does this mean? RESTeasy will automatically scan for @Provider and JAX-RS resource annotations on your bean class and register them as JAX-RS resources.
Here is what you have to do with your web.xml file
<web-app>
<display-name>Archetype Created Web Application</display-name>
<listener>
<listener-class>org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class>
</listener>
<listener>
<listener-class>org.jboss.resteasy.plugins.spring.SpringContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>Resteasy</servlet-name>
<servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Resteasy</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
The SpringContextLoaderListener must be declared after ResteasyBootstrap as it uses ServletContext attributes initialized by it.
If you do not use a Spring ContextLoaderListener to create your bean factories, then 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 attributes org.jboss.resteasy.spi.ResteasyProviderFactory and org.jboss.resteasy.spi.Registry. (Really the string FQN of these classes). There is also a org.jboss.resteasy.plugins.spring.SpringBeanProcessorServletAware, that will automatically inject references to the Registry and ResteasyProviderFactory from the Servlet Context. (that is, if you have used RestasyBootstrap to bootstrap Resteasy).
Our Spring integration supports both singletons and the "prototype" scope. RESTEasy handles injecting @Context references. Constructor injection is not supported though. Also, with the "prototype" scope, RESTEasy will inject any @*Param annotated fields or setters before the request is dispatched.
NOTE: You can only use auto-proxied beans with our base Spring integration. You will have undesirable affects if you are doing handcoded proxying with Spring, i.e., with ProxyFactoryBean. If you are using auto-proxied beans, you will be ok.
41.2. Spring MVC Integration
RESTEasy can also integrate with the Spring DispatcherServlet. The advantages of using this are that you have a simpler web.xml file, you can dispatch to either Spring controllers or Resteasy from under the same base URL, and finally, the most important, you can use Spring ModelAndView objects as return arguments from @GET resource methods. Setup requires you using the Spring DispatcherServlet in your web.xml file, as well as importing the springmvc-resteasy.xml file into your base Spring beans xml file. Here's an example web.xml file:
<web-app>
<display-name>Archetype Created Web Application</display-name>
<servlet>
<servlet-name>Spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet;</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Spring</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
Then within your main Spring beans xml, import the springmvc-resteasy.xml file
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
">
<!-- Import basic SpringMVC Resteasy integration -->
<import resource="classpath:springmvc-resteasy.xml"/>
....
You can specify resteasy configuration options by overriding the resteasy.deployment bean which is an instance of org.jboss.resteasy.spi.ResteasyDeployment. Here's an example of adding media type suffix mappings as well as enabling the Resteasy asynchronous job service.
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
">
<!-- Import basic SpringMVC Resteasy integration -->
<import resource="classpath:springmvc-resteasy.xml" />
<!-- override the bean definition for deployment -->
<bean id="resteasy.deployment" class="org.jboss.resteasy.spi.ResteasyDeployment" init-method="start" destroy-method="stop">
<property name="asyncJobServiceEnabled" value="true"/>
<property name="mediaTypeMappings">
<map>
<entry key="json" value="application/json" />
<entry key="xml" value="application/xml" />
</map>
</property>
</bean>
...
分享到:
相关推荐
Spring整合RestEasy示例工程源码,Spring+Jetty+RestEasy
Resteasy + Spring + Netty sample Inject resteasy provider / controllers as spring bean Authentication Run at Main.java Test http://localhost:8082/resteasy/hello/world 教程 jax-rs规范用法: ...
另外,此RESTEasy Spring Boot启动程序将按预期方式与Spring集成,这意味着每个也是Spring Bean的JAX-RS REST资源都将被自动自动扫描,集成和可用。 产品特点 为Spring Boot应用程序启用RESTEasy 作为Spring bean...
resteasy-spring-netty Resteasy + Spring + Netty sample Inject resteasy provider / controllers as spring bean Authentication ===================== Run at Main.java Test 教程 jax-rs规范用法: resteasy ...
POC 网址 Resteasy Jaxrs 1.0 Spring
宁静的春天 Resteasy + Spring + Netty示例 作为spring bean注入resteasy提供者/控制器 验证 ==================== 在Main.java中运行 测试
另外,此RESTEasy Spring Boot启动程序将按预期方式与Spring集成,这意味着每个也是Spring Bean的JAX-RS REST资源都将被自动自动扫描,集成和可用。 特征 为Spring Boot应用程序启用RESTEasy 作为Spring bean支持...
Jboss EAP 6(Jboss 7)RestEasy 3.09 Spring 3.2.5 Swagger 2.0与Web.xml和Bean配置的Swagger UI集成 为此,您必须将RestEasy安装升级到3.09 说明来自: : Resteasy与JBoss AS 7捆绑在一起。您可能需要在AS7中...
该项目为 Spring Boot 应用程序提供 RESTEasy 自动配置。入门构建此项目并将其安装到您的 Maven 存储库中: $ mvn install然后,您应该在应用程序的build.gradle或pom.xml添加对org.springframework.boot:spring-...
appengine-骨架 这是从 appengine-skeleton 原型生成的应用程序。
resteasy
详细描述了restEasy在servlet3.0前后的不同使用方法;restEasy 结合httpServer 无需容器开发;restEasy的通用差错拦截;附详细实现源码!
resteasy讲解
利用RestEasy和Jetty服务器搭建轻量级的RESTful web service的例程
resteasy入门级文档、如何使用Restful进行WebService的开发简介及相关RestEasy相关资源的链接
resteasy简单demo使用的jar包
RESTEasy入门经典.docx
resteasy不使用tomcat使用netty实现,实现了高性能,也可以不需要tomcat的容器,一个主函数就能执行
RESTEasy + Spring integration example http://localhost:8080/RESTfulExample/customer/print JBoss RESTEasy 是一个用来使用Java语言开发 RESTFul Web服务的框架。
使用RESTEasy+guice实现上传下载文件