美文网首页
Spring Bean Scopes: Bean 实例生成方式与

Spring Bean Scopes: Bean 实例生成方式与

作者: 光剑书架上的书 | 来源:发表于2021-07-16 15:01 被阅读0次

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 实例生成方式与

      本文链接:https://www.haomeiwen.com/subject/ewcbpltx.html