当前位置: 首页 > news >正文

网站模板简易修改单位网络建设的设计方案

网站模板简易修改,单位网络建设的设计方案,太原建站网站模板,抖音视频排名优化为了帮助大家更深入的理解bean的作用域#xff0c;特意将BeanDefinition的双例支持留到本章节中#xff0c;创建Bean,相关Reader读取等逻辑都有所改动。 内容介绍 在Spring中#xff0c;Bean的作用域#xff08;Scope#xff09;定义了Bean的生命周期和可见性。包括单例和…          为了帮助大家更深入的理解bean的作用域特意将BeanDefinition的双例支持留到本章节中创建Bean,相关Reader读取等逻辑都有所改动。 内容介绍 在Spring中Bean的作用域Scope定义了Bean的生命周期和可见性。包括单例和原型在本章节中我们将为Bean添加多例的支持下面是Prototype作用域的几个特征介绍 1. 多例Prototype Bean的prototype作用域表示每次从容器中获取该Bean时都会创建一个新的实例。每个请求或依赖注入都会导致创建一个全新的Bean对象。 2. 不受Spring容器管理 prototype作用域的Bean实例不受Spring容器的管理容器在创建Bean之后不会再跟踪它。这意味着Spring容器不会负责释放或销毁prototype作用域的Bean。一旦Bean被创建并交给调用者调用者负责Bean的生命周期包括销毁。 3. 适用场景 prototype作用域适用于那些每次获取实例时都需要全新状态的Bean例如HTTP请求的处理器或线程池中的任务。这样可以确保每次获取的Bean都是独立的不会影响其他实例。 这里设计到设计模式中的原型模式形象地说可以将prototype作用域的Bean比喻为一个不断复制的模具。每次你需要一个新的Bean实例时Spring容器会根据模具再次制作一个全新的Bean。这个模具本身不受容器管理而是由你自己管理它的生命周期。这与singleton作用域的Bean不同后者是像一个单一的实例化对象由容器管理其生命周期。   prototype作用域 可见prototype类型的bean并不受spring容器的管理你需要自己负责销毁或释放这些Bean实例以防止内存泄漏。  代码分支 GitHub - yihuiaa/little-spring: 剖析Spring源码包括常见特性IOC、AOP、三级缓存等...剖析Spring源码包括常见特性IOC、AOP、三级缓存等... Contribute to yihuiaa/little-spring development by creating an account on GitHub.https://github.com/yihuiaa/little-spring 核心代码 BeanDefinition private String scope SCOPE_SINGLETON;private boolean singleton true;private boolean prototype false;public static String SCOPE_SINGLETON singleton;public static String SCOPE_PROTOTYPE prototype;public void setScope(String scope) {this.scope scope;this.singleton SCOPE_SINGLETON.equals(scope);this.prototype SCOPE_PROTOTYPE.equals(scope);}public boolean isSingleton() {return this.singleton;}public boolean isPrototype() {return this.prototype;} AbstractAutowireCapableBeanFactory#doCreateBean() ... protected Object doCreateBean(String beanName, BeanDefinition beanDefinition) {Object bean null;try {bean createBeanInstance(beanDefinition);//为bean填充属性applyPropertyValues(beanName, bean, beanDefinition);//执行bean的初始化方法和BeanPostProcessor的前置和后置处理方法initializeBean(beanName, bean, beanDefinition);} catch (Exception e) {throw new BeansException(Instantiation of bean failed, e);}//注册有销毁方法的beanregisterDisposableBeanIfNecessary(beanName, bean, beanDefinition);if (beanDefinition.isSingleton()) {addSingleton(beanName, bean);}return bean;} ... AbstractAutowireCapableBeanFactory#registerDisposableBeanIfNecessary() /*** 注册有销毁方法的bean即bean继承自DisposableBean或有自定义的销毁方法** param beanName* param bean* param beanDefinition*/protected void registerDisposableBeanIfNecessary(String beanName, Object bean, BeanDefinition beanDefinition) {//只有singleton类型bean会执行销毁方法if (beanDefinition.isSingleton()) {if (bean instanceof DisposableBean || StrUtil.isNotEmpty(beanDefinition.getDestroyMethodName())) {registerDisposableBean(beanName, new DisposableBeanAdapter(bean, beanName, beanDefinition));}}}测试 prototype-bean.xml ?xml version1.0 encodingUTF-8? beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexmlns:contexthttp://www.springframework.org/schema/contextxsi:schemaLocationhttp://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-4.0.xsdbean idcar classbean.Car scopeprototypeproperty namename valueRolls-Royce//bean/beans 单元测试 public class PrototypeBeanTest {Testpublic void testPrototype() throws Exception {ClassPathXmlApplicationContext applicationContext new ClassPathXmlApplicationContext(classpath:prototype-bean.xml);Car car1 applicationContext.getBean(car, Car.class);Car car2 applicationContext.getBean(car, Car.class);System.out.println(car1 car2);;} }测试结果 false Process finished with exit code 0
http://www.w-s-a.com/news/362222/

相关文章:

  • 企业网站开发文献综述加盟网网站建设策划书
  • 最便宜的网站空间网站建设和app开发
  • 承装承修承试材料在哪个网站做如何用虚拟主机建设网站
  • 如何建一个外贸网站网页设计零基础学习课程
  • 营销型外贸网站广州昆明建设网站制作
  • 网页制作网站素材项目建设全过程管理
  • 正能量网站下载柬埔寨网赌网站开发
  • 如何免费建设公司网站广州传业建设有限公司网站
  • 织梦做的网站快照被攻击张家口网站建设公司
  • 平顶山公司网站建设南昌网站seo多少钱
  • 网站开发要先买服务器吗建设婚恋网站用什么搭建
  • 我想自己在网站上发文章 怎样做wordpress站点安装
  • 北京模板网站开发全包昆明网站开发正规培训
  • 西咸新区建设环保网站谷歌风格wordpress
  • 嘉兴港区建设局网站2018年网站开发
  • 网站里图片做超链接专业开发网站报价单
  • server2003网站建设做销售记住这十句口诀
  • microsoft免费网站网站后台登陆路径
  • 贵州住房和城乡建设局网站做网站排名费用多少钱
  • 现在个人做网站还能盈利吗xampp用wordpress
  • 做网站 租服务器温岭建设公司网站
  • 四川住房和城乡建设厅网站官网做网站最贵
  • 右玉网站建设四川林峰脉建设工程有限公司网站
  • 网站推广小助手杭州百度百家号seo优化排名
  • 怎么做网站搜索框搜索网站备案拍照背景幕布
  • 建设部网站城市规划资质标准伊春网络推广
  • 如何设计酒店网站建设深圳市房地产信息系统平台
  • 伍佰亿网站怎么样网站建设前台后台设计
  • 做整装的网站北京哪个网站制作公司
  • 建设赚钱的网站福州便民生活网