Spring中Bean的作用域(Scope)

来源:互联网 发布:网络传销崩盘前兆 编辑:程序博客网 时间:2024/05/21 18:34

在Spring 5.0中支持以下六种Bean的作用域:

范围 描述 singleton (默认)每个Spring IOC容器中一个Bean定义只有一个实例对象。 prototype 一个Bean定义可以有多个对象实例 request 一个HTTP请求创建一个Bean的实例,该作用域只在web-aware Spring ApplicationContext中有效。 session 在一个HTTP会话的生命周期中,一个Bean的定义对应一个对象实例。该作用域只在Spring ApplicationContext中有效。 application 在ServletContext生命周期中定义一个Bean,该作用域只在web-aware Spring ApplicationContext中有效。 websocket 在一个WebSocket生命周期中定义一个Bean,该作用域只在web-aware Spring ApplicationContext中有效。

参考资料:
https://docs.spring.io/spring/docs/current/spring-framework-reference/core.html

原创粉丝点击