This is an automated email from the ASF dual-hosted git repository.

liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git


The following commit(s) were added to refs/heads/master by this push:
     new e622d17  [SCB-2024]support not resolve place holder when running in 
spring boot
e622d17 is described below

commit e622d17dd58866a5ea7d5800175c27ac6880fbcb
Author: liubao <[email protected]>
AuthorDate: Tue Jun 23 19:33:17 2020 +0800

    [SCB-2024]support not resolve place holder when running in spring boot
---
 .../core/ConfigurationSpringInitializer.java       | 15 +++++-----
 .../springmvc/client/SpringmvcClientIT.java}       | 33 +++++++++++++++-------
 .../demo-spring-boot-springmvc-server/pom.xml      |  2 +-
 .../springmvc/server/SpringmvcServer.java          | 17 +++++++++++
 .../src/main/resources/application.yml             |  2 ++
 .../{application.yml => microservice.yaml}         |  5 ++--
 6 files changed, 54 insertions(+), 20 deletions(-)

diff --git 
a/core/src/main/java/org/apache/servicecomb/core/ConfigurationSpringInitializer.java
 
b/core/src/main/java/org/apache/servicecomb/core/ConfigurationSpringInitializer.java
index 612e995..85647d3 100644
--- 
a/core/src/main/java/org/apache/servicecomb/core/ConfigurationSpringInitializer.java
+++ 
b/core/src/main/java/org/apache/servicecomb/core/ConfigurationSpringInitializer.java
@@ -178,6 +178,11 @@ public class ConfigurationSpringInitializer extends 
PropertyPlaceholderConfigure
     }
 
     ConfigurableEnvironment configurableEnvironment = 
(ConfigurableEnvironment) environment;
+
+    if (ignoreResolveFailure()) {
+      configurableEnvironment.setIgnoreUnresolvableNestedPlaceholders(true);
+    }
+
     for (PropertySource<?> propertySource : 
configurableEnvironment.getPropertySources()) {
       getProperties(configurableEnvironment, propertySource, 
configFromSpringBoot);
     }
@@ -201,13 +206,9 @@ public class ConfigurationSpringInitializer extends 
PropertyPlaceholderConfigure
         try {
           configFromSpringBoot.put(propertyName, 
environment.getProperty(propertyName, Object.class));
         } catch (Exception e) {
-          if (ignoreResolveFailure()) {
-            LOGGER.warn("set up spring property source failed.", e);
-          } else {
-            throw new RuntimeException(
-                "set up spring property source failed.If you still want to 
start up the application and ignore errors, you can set 
servicecomb.config.ignoreResolveFailure to true.",
-                e);
-          }
+          throw new RuntimeException(
+              "set up spring property source failed.If you still want to start 
up the application and ignore errors, you can set 
servicecomb.config.ignoreResolveFailure to true.",
+              e);
         }
       }
       return;
diff --git 
a/demo/demo-spring-boot-provider/demo-spring-boot-springmvc-server/src/main/java/org/apache/servicecomb/springboot/springmvc/server/SpringmvcServer.java
 
b/demo/demo-spring-boot-provider/demo-spring-boot-springmvc-client/src/test/java/org/apache/servicecomb/springboot/springmvc/client/SpringmvcClientIT.java
similarity index 54%
copy from 
demo/demo-spring-boot-provider/demo-spring-boot-springmvc-server/src/main/java/org/apache/servicecomb/springboot/springmvc/server/SpringmvcServer.java
copy to 
demo/demo-spring-boot-provider/demo-spring-boot-springmvc-client/src/test/java/org/apache/servicecomb/springboot/springmvc/client/SpringmvcClientIT.java
index fadd276..279d6da 100644
--- 
a/demo/demo-spring-boot-provider/demo-spring-boot-springmvc-server/src/main/java/org/apache/servicecomb/springboot/springmvc/server/SpringmvcServer.java
+++ 
b/demo/demo-spring-boot-provider/demo-spring-boot-springmvc-client/src/test/java/org/apache/servicecomb/springboot/springmvc/client/SpringmvcClientIT.java
@@ -15,18 +15,31 @@
  * limitations under the License.
  */
 
-package org.apache.servicecomb.springboot.springmvc.server;
+package org.apache.servicecomb.springboot.springmvc.client;
 
-import org.apache.servicecomb.springboot2.starter.EnableServiceComb;
-import org.springframework.boot.WebApplicationType;
-import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.boot.builder.SpringApplicationBuilder;
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
 
-@SpringBootApplication
-@EnableServiceComb
-public class SpringmvcServer {
+import org.apache.servicecomb.demo.TestMgr;
+import org.junit.Before;
+import org.junit.Test;
 
-  public static void main(final String[] args) throws Exception {
-    new 
SpringApplicationBuilder().sources(SpringmvcServer.class).web(WebApplicationType.NONE).build().run(args);
+public class SpringmvcClientIT {
+  @Before
+  public void setUp() throws Exception {
+    TestMgr.errors().clear();
+  }
+
+  @Test
+  public void clientGetsNoError() throws Exception {
+    try {
+      SpringmvcClient.main(new String[0]);
+
+      assertThat(TestMgr.errors().isEmpty(), is(true));
+    } catch (Throwable e) {
+      e.printStackTrace();
+      fail("test case failed, message=" + e.getMessage());
+    }
   }
 }
diff --git 
a/demo/demo-spring-boot-provider/demo-spring-boot-springmvc-server/pom.xml 
b/demo/demo-spring-boot-provider/demo-spring-boot-springmvc-server/pom.xml
index 8d8674f..c82e534 100644
--- a/demo/demo-spring-boot-provider/demo-spring-boot-springmvc-server/pom.xml
+++ b/demo/demo-spring-boot-provider/demo-spring-boot-springmvc-server/pom.xml
@@ -22,7 +22,7 @@
   <modelVersion>4.0.0</modelVersion>
 
   <artifactId>demo-spring-boot-springmvc-server</artifactId>
-  <name>Java Chassis::Demo::Spring Boot::Spring MVC Client</name>
+  <name>Java Chassis::Demo::Spring Boot::Spring MVC Server</name>
   <parent>
     <groupId>org.apache.servicecomb.demo</groupId>
     <artifactId>demo-spring-boot</artifactId>
diff --git 
a/demo/demo-spring-boot-provider/demo-spring-boot-springmvc-server/src/main/java/org/apache/servicecomb/springboot/springmvc/server/SpringmvcServer.java
 
b/demo/demo-spring-boot-provider/demo-spring-boot-springmvc-server/src/main/java/org/apache/servicecomb/springboot/springmvc/server/SpringmvcServer.java
index fadd276..b369ef8 100644
--- 
a/demo/demo-spring-boot-provider/demo-spring-boot-springmvc-server/src/main/java/org/apache/servicecomb/springboot/springmvc/server/SpringmvcServer.java
+++ 
b/demo/demo-spring-boot-provider/demo-spring-boot-springmvc-server/src/main/java/org/apache/servicecomb/springboot/springmvc/server/SpringmvcServer.java
@@ -17,16 +17,33 @@
 
 package org.apache.servicecomb.springboot.springmvc.server;
 
+import org.apache.servicecomb.core.SCBEngine;
 import org.apache.servicecomb.springboot2.starter.EnableServiceComb;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.boot.WebApplicationType;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.builder.SpringApplicationBuilder;
 
+import com.netflix.config.DynamicPropertyFactory;
+
 @SpringBootApplication
 @EnableServiceComb
 public class SpringmvcServer {
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(SpringmvcServer.class);
 
   public static void main(final String[] args) throws Exception {
     new 
SpringApplicationBuilder().sources(SpringmvcServer.class).web(WebApplicationType.NONE).build().run(args);
+
+    assertPropertyCorrect();
+  }
+
+  private static void assertPropertyCorrect() {
+    String result = DynamicPropertyFactory.getInstance()
+        .getStringProperty("test.unresolved.placeholder", null).get();
+    if (!"jdbc:postgresql://${ip}:${port}/pt".equals(result)) {
+      LOGGER.error("tests for configuration error, stop");
+      SCBEngine.getInstance().destroy();
+    }
   }
 }
diff --git 
a/demo/demo-spring-boot-provider/demo-spring-boot-springmvc-server/src/main/resources/application.yml
 
b/demo/demo-spring-boot-provider/demo-spring-boot-springmvc-server/src/main/resources/application.yml
index c21992c..d45f5bc 100644
--- 
a/demo/demo-spring-boot-provider/demo-spring-boot-springmvc-server/src/main/resources/application.yml
+++ 
b/demo/demo-spring-boot-provider/demo-spring-boot-springmvc-server/src/main/resources/application.yml
@@ -17,3 +17,5 @@
 
 server:
   port: 7999
+
+test.unresolved.placeholder: jdbc:postgresql://${ip}:${port}/pt
\ No newline at end of file
diff --git 
a/demo/demo-spring-boot-provider/demo-spring-boot-springmvc-server/src/main/resources/application.yml
 
b/demo/demo-spring-boot-provider/demo-spring-boot-springmvc-server/src/main/resources/microservice.yaml
similarity index 94%
copy from 
demo/demo-spring-boot-provider/demo-spring-boot-springmvc-server/src/main/resources/application.yml
copy to 
demo/demo-spring-boot-provider/demo-spring-boot-springmvc-server/src/main/resources/microservice.yaml
index c21992c..141c0d4 100644
--- 
a/demo/demo-spring-boot-provider/demo-spring-boot-springmvc-server/src/main/resources/application.yml
+++ 
b/demo/demo-spring-boot-provider/demo-spring-boot-springmvc-server/src/main/resources/microservice.yaml
@@ -15,5 +15,6 @@
 ## limitations under the License.
 ## ---------------------------------------------------------------------------
 
-server:
-  port: 7999
+servicecomb:
+  config:
+    ignoreResolveFailure: true
\ No newline at end of file

Reply via email to