This is an automated email from the ASF dual-hosted git repository.
liubao pushed a commit to branch 2.8.x
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git
The following commit(s) were added to refs/heads/2.8.x by this push:
new 8027dc319 [SCB-2868]bean init can specify user defined locations
(#4274)
8027dc319 is described below
commit 8027dc319b23352816241e41cd732cb17b8b13f0
Author: liubao68 <[email protected]>
AuthorDate: Thu Mar 28 10:19:01 2024 +0800
[SCB-2868]bean init can specify user defined locations (#4274)
---
.../servicecomb/foundation/common/utils/BeanUtils.java | 13 +++++++++----
.../springboot2/starter/ServiceCombSpringConfiguration.java | 2 +-
.../rest/servlet/TestCseXmlWebApplicationContext.java | 12 ++++++------
3 files changed, 16 insertions(+), 11 deletions(-)
diff --git
a/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/utils/BeanUtils.java
b/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/utils/BeanUtils.java
index 4f0b91770..85193e979 100644
---
a/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/utils/BeanUtils.java
+++
b/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/utils/BeanUtils.java
@@ -36,12 +36,9 @@ import
org.springframework.context.support.ClassPathXmlApplicationContext;
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";
@@ -65,6 +62,14 @@ public final class BeanUtils {
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));
}
diff --git
a/spring-boot/spring-boot-starters/java-chassis-spring-boot-starter/src/main/java/org/apache/servicecomb/springboot2/starter/ServiceCombSpringConfiguration.java
b/spring-boot/spring-boot-starters/java-chassis-spring-boot-starter/src/main/java/org/apache/servicecomb/springboot2/starter/ServiceCombSpringConfiguration.java
index 89cf311a3..94b27999e 100644
---
a/spring-boot/spring-boot-starters/java-chassis-spring-boot-starter/src/main/java/org/apache/servicecomb/springboot2/starter/ServiceCombSpringConfiguration.java
+++
b/spring-boot/spring-boot-starters/java-chassis-spring-boot-starter/src/main/java/org/apache/servicecomb/springboot2/starter/ServiceCombSpringConfiguration.java
@@ -25,7 +25,7 @@ import org.springframework.context.annotation.Configuration;
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) {
diff --git
a/transports/transport-rest/transport-rest-servlet/src/test/java/org/apache/servicecomb/transport/rest/servlet/TestCseXmlWebApplicationContext.java
b/transports/transport-rest/transport-rest-servlet/src/test/java/org/apache/servicecomb/transport/rest/servlet/TestCseXmlWebApplicationContext.java
index e80d8bb6d..93cd301c0 100644
---
a/transports/transport-rest/transport-rest-servlet/src/test/java/org/apache/servicecomb/transport/rest/servlet/TestCseXmlWebApplicationContext.java
+++
b/transports/transport-rest/transport-rest-servlet/src/test/java/org/apache/servicecomb/transport/rest/servlet/TestCseXmlWebApplicationContext.java
@@ -49,7 +49,7 @@ public class TestCseXmlWebApplicationContext {
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
@@ -57,7 +57,7 @@ public class TestCseXmlWebApplicationContext {
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
@@ -71,7 +71,7 @@ public class TestCseXmlWebApplicationContext {
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
@@ -84,7 +84,7 @@ public class TestCseXmlWebApplicationContext {
};
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
@@ -97,7 +97,7 @@ public class TestCseXmlWebApplicationContext {
};
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
@@ -110,7 +110,7 @@ public class TestCseXmlWebApplicationContext {
};
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