Java Jersey Spring集成和范围
我尝试了Spring和Jersey的集成,但我对范围感到困惑。 对于spring,默认范围是Singleton。 对于Jersey,默认范围是Request 例如:Java Jersey Spring集成和范围,java,spring,jersey,jax-rs,jersey-2.0,Java,Spring,Jersey,Jax Rs,Jersey 2.0,我尝试了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"
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!";
}
}
组件注释使类成为Springbean。Springbean是默认的单例,jersey是默认的请求范围
问题是:这个bean的范围是什么
- 如果我把@Scope(“request”)放进去,它是否会变成“request Scope”
- 如果我不放@Scope(“request”),那么实际的作用域是什么
MyResource
作为Springbean,因此范围由Spring处理
- 使用@Scope(“request”):bean的作用域将是“request”
- 没有@Scope(“request”):bean的作用域将是“singleton”(spring默认值)