Jersey是一款优秀的webservice框架,它同时支持soap和rest两种协议,并且系出名门(oracle)。美中不足的是:Jersey是基于Servlet实现的,具备Servlet的单例特性,有线程安全问题的隐患(这点跟Struts1.x很像)。 java
@Component @Scope("request") @Path("/WebServiceDemoImpl") public class WebServiceDemoImpl implements WebServiceDemo{
加入@Scope("request")注解后,Spring会针对每个request请求都生成新的Jersey服务类实例(实际上spring并非采用这种机制保障线程安全的,我这么说是为了便于理解)。但使用request scope还要在web.xml文件中加入Spring RequsetContextListener的配置: web
<web-app> ... <listener> <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class> </listener> ... </web-app>
(2) prototype scope(推荐): spring
@Component @Scope("prototype") @Path("/WebServiceDemoImpl") public class WebServiceDemoImpl implements WebServiceDemo{加入@Scope("prototype")注解后,Spring会针对每个request请求都生成新的Jersey服务类实例。使用此方法不须要配置Spring RequsetContextListener,较为简便,推荐!