Spring Bean Scopes: Bean 实例生成方式与生命周期
Posted 东海陈光剑
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Spring Bean Scopes: Bean 实例生成方式与生命周期相关的知识,希望对你有一定的参考价值。
The life cycle and visibility of Spring Bean.
6 types of scopes
singleton
prototype
request
session
application
websocket
The last four scopes mentioned, request, session, application and websocket, are only available in a web-aware application.
使用例子
@Bean@Scope("singleton")publicPersonpersonSingleton(){
return new Person();
}
@Service
@Scope("prototype")
public class SpecificationParserClickHouse implements SpecificationParser {
@Resource
FieldFeatureBuilder fieldFeatureBuilder;
ListspecList;
IQuerySpecification spec =null;
...
}
参考资料
https://www.baeldung.com/spring-bean-scopes
以上是关于Spring Bean Scopes: Bean 实例生成方式与生命周期的主要内容,如果未能解决你的问题,请参考以下文章