【玩转Spring各种作用域Bean Scope及源码分析】3.2 查找web作用域bean
public abstract class AbstractBeanFactory {protected <T> T doGetBean(...) {// ...// 判断是否是单例if (mbd.isSingleton()) {// ...}// 判断是否是原型else if (mbd.isPrototype()) {Object prototypeInstance = null;try {// 不存在什么缓存池,直接创建bean实例返回prototypeInstance = createBean(beanName, mbd, args);}}// 其它作用域bean,如上面的web作用域else {String scopeName = mbd.getScope();Scope scope = this.scopes.get(scopeName);if (scope == null) {throw new IllegalStateException("No Scope registered for scope name '" + scopeName + "'");}try {// 通过具体Scope的实现类获取bean对象Object scopedInstance = scope.get(beanName, () -> {beforePrototypeCreation(beanName);try {// 首次都还是会创建return createBean(beanName, mbd, args);}});}}}// ...}}
总结:Spring Scope Bean是Spring框架中用于管理Bean的作用域的机制,它定义了Bean的生命周期和实例化策略 。通过合理地选择Bean的作用域 , 可以优化应用的性能和资源利用率 。
推荐阅读
- Spring Boot Starter的原理
- Spring 七种事务传播性介绍
- 摩飞便携榨汁杯体验
- 简易版的SpringBoot是如何实现的!!!
- 钓鱼饵料指南:各种饵料特点与使用技巧
- 各种钢材的尺寸与重量大全
- 网络用语有那些各指什么意思 各种网络用词的意思
- Spring非常实用的技巧,你确定知道?
- 当年一瓶雪花膏闯天下,现在护肤用的各种水都是智商税吗?
- Java Lambda 表达式各种用法,你都会了吗