Skip to content

Commit

Permalink
Sofa default listable bean factory add (#1279)
Browse files Browse the repository at this point in the history
* update sofaark 2.2.7-SNAPSHOT

* support id in SofaDefaultListableBeanFactory

---------

Co-authored-by: 致节 <[email protected]>
  • Loading branch information
HzjNeverStop and 致节 authored Jan 12, 2024
1 parent f708c0c commit 1dc7854
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
}
}
2 changes: 1 addition & 1 deletion sofa-boot-project/sofaboot-dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<sofa.common.tools.version>2.1.0-SNAPSHOT</sofa.common.tools.version>
<sofa.bolt.version>1.6.6</sofa.bolt.version>
<sofa.hessian.version>3.5.1</sofa.hessian.version>
<sofa.ark.version>3.0.1-SNAPSHOT</sofa.ark.version>
<sofa.ark.version>2.2.7-SNAPSHOT</sofa.ark.version>
<sofa.lookout.version>1.6.1</sofa.lookout.version>
<!--3rd lib dependency-->
<spring.cloud.version>2023.0.0</spring.cloud.version>
Expand Down

0 comments on commit 1dc7854

Please sign in to comment.