Java Spring 服务默认范围
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25583355/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Spring Service default scope
提问by vdenotaris
Which is the default scope of a Spring 4@Service
?
哪个是Spring 4的默认范围@Service
?
Does it make sense designing a Serviceimplementation to store info about the current logged user (according to the current HTTP session), through class attributes(also by using the final
modifier)?
设计一个Service实现来存储有关当前登录用户的信息(根据当前HTTP session),通过类属性(也通过使用final
修饰符)是否有意义?
采纳答案by JB Nizet
Which is the default scope of a Spring 4 @Service?
Spring 4 @Service 的默认范围是哪个?
The default scope is singleton
默认范围是单例
It is reasonable to design a Service implementation in order to store some info, related to the current logged user (according to the current HTTP session)
设计一个 Service 实现来存储一些与当前登录用户相关的信息是合理的(根据当前的 HTTP 会话)
Yes. In that case, the service will have to have the scope "session". See http://docs.spring.io/spring/docs/current/spring-framework-reference/html/beans.html#beans-factory-scopes-other
是的。在这种情况下,服务必须具有“会话”范围。见http://docs.spring.io/spring/docs/current/spring-framework-reference/html/beans.html#beans-factory-scopes-other