From d852219632ced058f5c7cc890b559105e7d641ba Mon Sep 17 00:00:00 2001 From: xuchengsheng Date: Tue, 26 Sep 2023 15:21:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96InstantiationAwareBeanPostPro?= =?UTF-8?q?cessor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../README.md | 22 +++---------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/spring-interface-instantiationAwareBeanPostProcessor/README.md b/spring-interface-instantiationAwareBeanPostProcessor/README.md index cd18667..fd25437 100644 --- a/spring-interface-instantiationAwareBeanPostProcessor/README.md +++ b/spring-interface-instantiationAwareBeanPostProcessor/README.md @@ -352,10 +352,7 @@ protected T doGetBean( return createBean(beanName, mbd, args); } catch (BeansException ex) { - // 如果在创建bean过程中出现异常,从单例缓存中移除它 - // 这样做是为了防止循环引用的情况 - destroySingleton(beanName); - throw ex; + // ... [代码部分省略以简化] } }); // 对于某些bean(例如FactoryBeans),可能需要进一步处理以获取真正的bean实例 @@ -372,8 +369,7 @@ protected T doGetBean( ```java public Object getSingleton(String beanName, ObjectFactory singletonFactory) { - // 断言bean名称不能为空 - Assert.notNull(beanName, "Bean name must not be null"); + // ... [代码部分省略以简化] // 同步访问单例对象缓存,确保线程安全 synchronized (this.singletonObjects) { @@ -384,15 +380,6 @@ public Object getSingleton(String beanName, ObjectFactory singletonFactory) { if (singletonObject == null) { // ... [代码部分省略以简化] - // 在创建单例之前执行某些操作,如记录创建状态 - beforeSingletonCreation(beanName); - - boolean newSingleton = false; - boolean recordSuppressedExceptions = (this.suppressedExceptions == null); - if (recordSuppressedExceptions) { - this.suppressedExceptions = new LinkedHashSet<>(); - } - try { // 使用工厂创建新的单例实例 singletonObject = singletonFactory.getObject(); @@ -408,10 +395,7 @@ public Object getSingleton(String beanName, ObjectFactory singletonFactory) { // ... [代码部分省略以简化] } - // 如果成功创建了新的单例,将其加入缓存 - if (newSingleton) { - addSingleton(beanName, singletonObject); - } + // ... [代码部分省略以简化] } // 返回单例对象