Skip to content

Commit

Permalink
[SCB-2868]bean init can specify user defined locations (#4274)
Browse files Browse the repository at this point in the history
  • Loading branch information
liubao68 authored Mar 28, 2024
1 parent d38b9e9 commit 8027dc3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,9 @@
public final class BeanUtils {
private static final Logger LOGGER = LoggerFactory.getLogger(BeanUtils.class);

public static final String DEFAULT_BEAN_CORE_RESOURCE = "classpath*:META-INF/spring/scb-core-bean.xml";

public static final String DEFAULT_BEAN_NORMAL_RESOURCE = "classpath*:META-INF/spring/*.bean.xml";

public static final String[] DEFAULT_BEAN_RESOURCE = new String[] {DEFAULT_BEAN_CORE_RESOURCE
, DEFAULT_BEAN_NORMAL_RESOURCE};
public static final String[] DEFAULT_BEAN_RESOURCE = new String[] {DEFAULT_BEAN_NORMAL_RESOURCE};

public static final String SCB_SCAN_PACKAGE = "scb-scan-package";

Expand All @@ -65,6 +62,14 @@ public static void init(String... configLocations) {
context = new ClassPathXmlApplicationContext(locationSet.toArray(new String[0]));
}

public static void initWithoutDefault(String... configLocations) {
prepareServiceCombScanPackage();

Set<String> locationSet = new LinkedHashSet<>();
addBeanLocation(locationSet, configLocations);
context = new ClassPathXmlApplicationContext(locationSet.toArray(new String[0]));
}

public static void addBeanLocation(Set<String> locationSet, String... location) {
Arrays.stream(location).forEach(loc -> addBeanLocation(locationSet, loc));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import org.springframework.context.annotation.ImportResource;

@Configuration
@ImportResource({BeanUtils.DEFAULT_BEAN_CORE_RESOURCE, BeanUtils.DEFAULT_BEAN_NORMAL_RESOURCE})
@ImportResource({BeanUtils.DEFAULT_BEAN_NORMAL_RESOURCE})
class ServiceCombSpringConfiguration {
@Inject
public void setCseApplicationListener(SCBApplicationListener applicationListener) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ public void setup() {
public void testGetConfigLocationsEmpty() {
String[] result = context.getConfigLocations();
MatcherAssert.assertThat(result,
Matchers.arrayContaining(BeanUtils.DEFAULT_BEAN_CORE_RESOURCE, BeanUtils.DEFAULT_BEAN_NORMAL_RESOURCE));
Matchers.arrayContaining(BeanUtils.DEFAULT_BEAN_NORMAL_RESOURCE));
}

@Test
public void testGetConfigLocationsEmptyAndDefaultEmpty() {
context.setDefaultBeanResource(null);
String[] result = context.getConfigLocations();
MatcherAssert.assertThat(result,
Matchers.arrayContaining(BeanUtils.DEFAULT_BEAN_CORE_RESOURCE, BeanUtils.DEFAULT_BEAN_NORMAL_RESOURCE));
Matchers.arrayContaining(BeanUtils.DEFAULT_BEAN_NORMAL_RESOURCE));
}

@Test
Expand All @@ -71,7 +71,7 @@ public void testGetConfigLocationsComma() {

String[] result = context.getConfigLocations();
MatcherAssert.assertThat(result, Matchers
.arrayContaining(BeanUtils.DEFAULT_BEAN_CORE_RESOURCE, BeanUtils.DEFAULT_BEAN_NORMAL_RESOURCE, "a", "b"));
.arrayContaining(BeanUtils.DEFAULT_BEAN_NORMAL_RESOURCE, "a", "b"));
}

@Test
Expand All @@ -84,7 +84,7 @@ public void testGetConfigLocationsPartEmpty() {
};
String[] result = context.getConfigLocations();
MatcherAssert.assertThat(result, Matchers
.arrayContaining(BeanUtils.DEFAULT_BEAN_CORE_RESOURCE, BeanUtils.DEFAULT_BEAN_NORMAL_RESOURCE, "a", "b"));
.arrayContaining(BeanUtils.DEFAULT_BEAN_NORMAL_RESOURCE, "a", "b"));
}

@Test
Expand All @@ -97,7 +97,7 @@ public void testGetConfigLocationsLine() {
};
String[] result = context.getConfigLocations();
MatcherAssert.assertThat(result, Matchers
.arrayContaining(BeanUtils.DEFAULT_BEAN_CORE_RESOURCE, BeanUtils.DEFAULT_BEAN_NORMAL_RESOURCE, "a", "b"));
.arrayContaining(BeanUtils.DEFAULT_BEAN_NORMAL_RESOURCE, "a", "b"));
}

@Test
Expand All @@ -110,7 +110,7 @@ public void testGetConfigLocationsMix() {
};
String[] result = context.getConfigLocations();
MatcherAssert.assertThat(result, Matchers
.arrayContaining(BeanUtils.DEFAULT_BEAN_CORE_RESOURCE, BeanUtils.DEFAULT_BEAN_NORMAL_RESOURCE, "a", "b", "c"));
.arrayContaining(BeanUtils.DEFAULT_BEAN_NORMAL_RESOURCE, "a", "b", "c"));
}

@Test
Expand Down

0 comments on commit 8027dc3

Please sign in to comment.