[英]Jersey Spring Integration and Scopes
我尝试进行Spring和Jersey集成,但是我对范围感到困惑。 对于spring,默认范围是Singleton。 对于Jersey,默认范围是Request。
例如:
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
// The Java class will be hosted at the URI path "/myresource"
@Path("/myresource")
@Component
@Scope("request")
public class MyResource {
// The Java method will process HTTP GET requests
@GET
// The Java method will produce content identified by the MIME Media
// type "text/plain"
@Produces("text/plain")
public String getIt() {
return "Hi there!";
}
}
组件注释使该类成为Spring Bean.Spring bean是默认的Singleton,而jersey是默认的请求范围。
问题是:这个bean的作用域是什么。
如果我把@Scope(“ request”)放进去,它会变成“ request scope”。
如果我不输入@Scope(“ request”),实际范围是什么?
如您所说,您使MyResource
成为Spring Bean,因此作用域由Spring处理。
无论您在Spring上使用CXF还是Jersey,它们都仅用于JAX-RS端点编程(不适用于管理bean)。
编辑 :我已经在文档中找到它:
由于端点是Spring @Component,因此其生命周期由Spring管理,您可以@Autowired依赖项并使用@Value注入外部配置。 默认情况下,Jersey servlet将被注册并映射到/ *。 您可以通过将@ApplicationPath添加到ResourceConfig来更改映射。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.