[英]Jersey Spring Integration and Scopes
I try Spring and Jersey integration.But I'm confused about scopes. 我尝试进行Spring和Jersey集成,但是我对范围感到困惑。 For spring the default scope is Singleton.
对于spring,默认范围是Singleton。 And for Jersey default scope is Request.
对于Jersey,默认范围是Request。
For example: 例如:
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!";
}
}
Component annotation makes the class a Spring Bean.Spring bean is default Singleton and jersey is default request scope. 组件注释使该类成为Spring Bean.Spring bean是默认的Singleton,而jersey是默认的请求范围。
Here is the question: What is the scope for this bean. 问题是:这个bean的作用域是什么。
If I put @Scope("request") does it make "request scope". 如果我把@Scope(“ request”)放进去,它会变成“ request scope”。
And if I don't put @Scope("request") what is the actual scope? 如果我不输入@Scope(“ request”),实际范围是什么?
As you said, you make MyResource
a Spring Bean, so the scope is handled by Spring. 如您所说,您使
MyResource
成为Spring Bean,因此作用域由Spring处理。
Whether you use CXF or Jersey with Spring, these are only used for the JAX-RS endpoints programming (not for managing beans). 无论您在Spring上使用CXF还是Jersey,它们都仅用于JAX-RS端点编程(不适用于管理bean)。
EDIT : I've found it in the documentation: 编辑 :我已经在文档中找到它:
Since the Endpoint is a Spring @Component its lifecycle is managed by Spring and you can @Autowired dependencies and inject external configuration with @Value.
由于端点是Spring @Component,因此其生命周期由Spring管理,您可以@Autowired依赖项并使用@Value注入外部配置。 The Jersey servlet will be registered and mapped to /* by default.
默认情况下,Jersey servlet将被注册并映射到/ *。 You can change the mapping by adding @ApplicationPath to your ResourceConfig.
您可以通过将@ApplicationPath添加到ResourceConfig来更改映射。
link: 27.2 JAX-RS and Jersey 链接: 27.2 JAX-RS和Jersey
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.