From 1dc7854ef5c31330dba4c084d79fc553e868ca9a Mon Sep 17 00:00:00 2001 From: HzjNeverStop <441627022@qq.com> Date: Fri, 12 Jan 2024 16:01:02 +0800 Subject: [PATCH] Sofa default listable bean factory add (#1279) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * update sofaark 2.2.7-SNAPSHOT * support id in SofaDefaultListableBeanFactory --------- Co-authored-by: 致节 --- .../boot/isle/loader/DynamicSpringContextLoader.java | 1 + .../isle/loader/DynamicSpringContextLoaderTests.java | 4 ++-- .../boot/context/SofaDefaultListableBeanFactory.java | 11 +++++++++++ sofa-boot-project/sofaboot-dependencies/pom.xml | 2 +- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/boot/isle/loader/DynamicSpringContextLoader.java b/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/boot/isle/loader/DynamicSpringContextLoader.java index 2c4201555..cbeb918de 100644 --- a/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/boot/isle/loader/DynamicSpringContextLoader.java +++ b/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/boot/isle/loader/DynamicSpringContextLoader.java @@ -87,6 +87,7 @@ public void loadSpringContext(DeploymentDescriptor deployment, ClassLoader classLoader = deployment.getClassLoader(); SofaDefaultListableBeanFactory beanFactory = SofaSpringContextSupport.createBeanFactory(classLoader, this::createBeanFactory); + beanFactory.setId(deployment.getModuleName()); SofaGenericApplicationContext context = SofaSpringContextSupport.createApplicationContext(beanFactory, this::createApplicationContext); if (startupReporter != null) { diff --git a/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/test/java/com/alipay/sofa/boot/isle/loader/DynamicSpringContextLoaderTests.java b/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/test/java/com/alipay/sofa/boot/isle/loader/DynamicSpringContextLoaderTests.java index 71973ee17..b2d9ba0c0 100644 --- a/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/test/java/com/alipay/sofa/boot/isle/loader/DynamicSpringContextLoaderTests.java +++ b/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/test/java/com/alipay/sofa/boot/isle/loader/DynamicSpringContextLoaderTests.java @@ -28,7 +28,6 @@ import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.support.BeanDefinitionReader; -import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.context.ApplicationContext; import org.springframework.context.ConfigurableApplicationContext; @@ -103,10 +102,11 @@ void loadSpringContext() { assertThat(applicationContext.getEnvironment().getActiveProfiles()).containsOnly("test"); applicationContext.refresh(); - DefaultListableBeanFactory autowireCapableBeanFactory = (DefaultListableBeanFactory) applicationContext + SofaDefaultListableBeanFactory autowireCapableBeanFactory = (SofaDefaultListableBeanFactory) applicationContext .getAutowireCapableBeanFactory(); assertThat(autowireCapableBeanFactory.isAllowBeanDefinitionOverriding()).isTrue(); assertThat(autowireCapableBeanFactory).isInstanceOf(SofaDefaultListableBeanFactory.class); + assertThat(autowireCapableBeanFactory.getId()).isEqualTo("test"); } @Test diff --git a/sofa-boot-project/sofa-boot/src/main/java/com/alipay/sofa/boot/context/SofaDefaultListableBeanFactory.java b/sofa-boot-project/sofa-boot/src/main/java/com/alipay/sofa/boot/context/SofaDefaultListableBeanFactory.java index 9e8b9ee4e..18cfad609 100644 --- a/sofa-boot-project/sofa-boot/src/main/java/com/alipay/sofa/boot/context/SofaDefaultListableBeanFactory.java +++ b/sofa-boot-project/sofa-boot/src/main/java/com/alipay/sofa/boot/context/SofaDefaultListableBeanFactory.java @@ -17,6 +17,7 @@ package com.alipay.sofa.boot.context; import org.springframework.beans.factory.support.DefaultListableBeanFactory; +import org.springframework.util.ObjectUtils; /** * Default Implementation of {@link DefaultListableBeanFactory} in SOFABoot framework. @@ -28,4 +29,14 @@ * @since 4.0.0 */ public class SofaDefaultListableBeanFactory extends DefaultListableBeanFactory { + + private String id = ObjectUtils.identityToString(this); + + public void setId(String id) { + this.id = id; + } + + public String getId() { + return this.id; + } } diff --git a/sofa-boot-project/sofaboot-dependencies/pom.xml b/sofa-boot-project/sofaboot-dependencies/pom.xml index ede76043f..79eb71765 100644 --- a/sofa-boot-project/sofaboot-dependencies/pom.xml +++ b/sofa-boot-project/sofaboot-dependencies/pom.xml @@ -28,7 +28,7 @@ 2.1.0-SNAPSHOT 1.6.6 3.5.1 - 3.0.1-SNAPSHOT + 2.2.7-SNAPSHOT 1.6.1 2023.0.0