版权声明:大家好,我是笨笨,笨笨的笨,笨笨的笨,转载请注明出处,谢谢! https://blog.csdn.net/jx520/article/details/88964442
@Scope 注解
目前我用到的就是 单列 singleton
和多例 prototype
Spring 默认的是单列 singleton
通常使用情况:
@Service
直接默认就行,所以不用加@Scope
注解 顺便提醒一下,既然是单例。。。属性的值可是下一次访问还在哦
@Controller
控制层用多例 @Scope("prototype")
毕竟我们不想两个用户的访问结果互相串
如果有其它具体需求再具体分析
下面列出所有支持的类型:
Scope | Description |
---|---|
singleton | (Default) Scopes a single bean definition to a single object instance for each Spring IoC container. |
prototype | Scopes a single bean definition to any number of object instances. |
request | Scopes a single bean definition to the lifecycle of a single HTTP request. That is, each HTTP request has its own instance of a bean created off the back of a single bean definition. Only valid in the context of a web-aware Spring ApplicationContext. |
session | Scopes a single bean definition to the lifecycle of an HTTP Session. Only valid in the context of a web-aware Spring ApplicationContext. |
application | Scopes a single bean definition to the lifecycle of a ServletContext. Only valid in the context of a web-aware Spring ApplicationContext. |
websocket | Scopes a single bean definition to the lifecycle of a WebSocket. Only valid in the context of a web-aware Spring ApplicationContext. |