【发布时间】:2017-01-12 15:36:38
【问题描述】:
我尝试了 Spring 和 Jersey 集成。但我对范围感到困惑。 对于 spring,默认范围是 Singleton。 泽西岛的默认范围是请求。
例如:
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") 是否会成为“请求范围”。
如果我不输入 @Scope("request") 实际范围是什么?
【问题讨论】:
标签: java spring jersey jax-rs jersey-2.0