diff --git a/spring-cloud-modules/spring-cloud-config/pom.xml b/spring-cloud-modules/spring-cloud-config/pom.xml index 8f4498e0c6..efbf30d0b2 100644 --- a/spring-cloud-modules/spring-cloud-config/pom.xml +++ b/spring-cloud-modules/spring-cloud-config/pom.xml @@ -18,6 +18,8 @@ spring-cloud-config-server spring-cloud-config-client + spring-cloud-config-overriding-properties-client + spring-cloud-config-overriding-properties-server @@ -36,4 +38,4 @@ 2021.0.3 - \ No newline at end of file + diff --git a/spring-cloud-modules/spring-cloud-config/spring-cloud-config-overriding-properties-client/pom.xml b/spring-cloud-modules/spring-cloud-config/spring-cloud-config-overriding-properties-client/pom.xml new file mode 100644 index 0000000000..d297e5b44d --- /dev/null +++ b/spring-cloud-modules/spring-cloud-config/spring-cloud-config-overriding-properties-client/pom.xml @@ -0,0 +1,40 @@ + + + 4.0.0 + spring-cloud-config-overriding-properties-client + spring-cloud-config-overriding-properties-client + + + com.baeldung.spring.cloud + spring-cloud-config + 1.0-SNAPSHOT + + + + + org.springframework.cloud + spring-cloud-starter-config + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/spring-cloud-modules/spring-cloud-config/spring-cloud-config-overriding-properties-client/src/main/java/com/baeldung/spring/cloud/config/overridingproperties/Client.java b/spring-cloud-modules/spring-cloud-config/spring-cloud-config-overriding-properties-client/src/main/java/com/baeldung/spring/cloud/config/overridingproperties/Client.java new file mode 100644 index 0000000000..c0c5f768bc --- /dev/null +++ b/spring-cloud-modules/spring-cloud-config/spring-cloud-config-overriding-properties-client/src/main/java/com/baeldung/spring/cloud/config/overridingproperties/Client.java @@ -0,0 +1,14 @@ +package com.baeldung.spring.cloud.config.overridingproperties; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Client { + + public static void main(String[] args) { + SpringApplication.run(Client.class, args); + } +} + + diff --git a/spring-cloud-modules/spring-cloud-config/spring-cloud-config-overriding-properties-client/src/main/java/com/baeldung/spring/cloud/config/overridingproperties/HelloController.java b/spring-cloud-modules/spring-cloud-config/spring-cloud-config-overriding-properties-client/src/main/java/com/baeldung/spring/cloud/config/overridingproperties/HelloController.java new file mode 100644 index 0000000000..c48b3d2b5c --- /dev/null +++ b/spring-cloud-modules/spring-cloud-config/spring-cloud-config-overriding-properties-client/src/main/java/com/baeldung/spring/cloud/config/overridingproperties/HelloController.java @@ -0,0 +1,33 @@ +package com.baeldung.spring.cloud.config.overridingproperties; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class HelloController { + + @Value("${hello}") + private String hello; + + @Value("${welcome}") + private String welcome; + + @Value("${shared-property}") + private String shared; + + @GetMapping("hello") + public String hello() { + return this.hello; + } + + @GetMapping("welcome") + public String welcome() { + return this.welcome; + } + + @GetMapping("shared") + public String shared() { + return this.shared; + } +} diff --git a/spring-cloud-modules/spring-cloud-config/spring-cloud-config-overriding-properties-client/src/main/resources/application-development.properties b/spring-cloud-modules/spring-cloud-config/spring-cloud-config-overriding-properties-client/src/main/resources/application-development.properties new file mode 100644 index 0000000000..0dd3e1bb91 --- /dev/null +++ b/spring-cloud-modules/spring-cloud-config/spring-cloud-config-overriding-properties-client/src/main/resources/application-development.properties @@ -0,0 +1 @@ +hello=Hello local property! diff --git a/spring-cloud-modules/spring-cloud-config/spring-cloud-config-overriding-properties-client/src/main/resources/application.properties b/spring-cloud-modules/spring-cloud-config/spring-cloud-config-overriding-properties-client/src/main/resources/application.properties new file mode 100644 index 0000000000..e4ff6e0550 --- /dev/null +++ b/spring-cloud-modules/spring-cloud-config/spring-cloud-config-overriding-properties-client/src/main/resources/application.properties @@ -0,0 +1,3 @@ +spring.cloud.config.name=baeldung +spring.config.import=optional:configserver:http://localhost:8081 +app.hello=Hello, overriden local property! diff --git a/spring-cloud-modules/spring-cloud-config/spring-cloud-config-overriding-properties-client/src/test/java/com/baeldung/spring/cloud/config/client/SpringContextLiveTest.java b/spring-cloud-modules/spring-cloud-config/spring-cloud-config-overriding-properties-client/src/test/java/com/baeldung/spring/cloud/config/client/SpringContextLiveTest.java new file mode 100644 index 0000000000..ca029b2843 --- /dev/null +++ b/spring-cloud-modules/spring-cloud-config/spring-cloud-config-overriding-properties-client/src/test/java/com/baeldung/spring/cloud/config/client/SpringContextLiveTest.java @@ -0,0 +1,15 @@ +package com.baeldung.spring.cloud.config.client; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +@ExtendWith(SpringExtension.class) +@SpringBootTest +public class SpringContextLiveTest { + + @Test + public void contextLoads() { + } +} diff --git a/spring-cloud-modules/spring-cloud-config/spring-cloud-config-overriding-properties-server/pom.xml b/spring-cloud-modules/spring-cloud-config/spring-cloud-config-overriding-properties-server/pom.xml new file mode 100644 index 0000000000..bcaa64e0d1 --- /dev/null +++ b/spring-cloud-modules/spring-cloud-config/spring-cloud-config-overriding-properties-server/pom.xml @@ -0,0 +1,31 @@ + + + 4.0.0 + spring-cloud-config-overriding-properties-server + spring-cloud-config-overriding-properties-server + + + com.baeldung.spring.cloud + spring-cloud-config + 1.0-SNAPSHOT + + + + + org.springframework.cloud + spring-cloud-config-server + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/spring-cloud-modules/spring-cloud-config/spring-cloud-config-overriding-properties-server/src/main/java/com/baeldung/spring/cloud/config/overridingproperties/ConfigServer.java b/spring-cloud-modules/spring-cloud-config/spring-cloud-config-overriding-properties-server/src/main/java/com/baeldung/spring/cloud/config/overridingproperties/ConfigServer.java new file mode 100644 index 0000000000..a8e2f80616 --- /dev/null +++ b/spring-cloud-modules/spring-cloud-config/spring-cloud-config-overriding-properties-server/src/main/java/com/baeldung/spring/cloud/config/overridingproperties/ConfigServer.java @@ -0,0 +1,14 @@ +package com.baeldung.spring.cloud.config.overridingproperties; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.config.server.EnableConfigServer; + +@SpringBootApplication +@EnableConfigServer +public class ConfigServer { + + public static void main(String[] args) { + SpringApplication.run(ConfigServer.class, args); + } +} diff --git a/spring-cloud-modules/spring-cloud-config/spring-cloud-config-overriding-properties-server/src/main/resources/application.properties b/spring-cloud-modules/spring-cloud-config/spring-cloud-config-overriding-properties-server/src/main/resources/application.properties new file mode 100644 index 0000000000..84c63795d5 --- /dev/null +++ b/spring-cloud-modules/spring-cloud-config/spring-cloud-config-overriding-properties-server/src/main/resources/application.properties @@ -0,0 +1,3 @@ +server.port=8081 +spring.cloud.config.server.native.search-locations=classpath:/config +#spring.cloud.config.server.overrides.hello=Hello Jane Doe - application.properties! diff --git a/spring-cloud-modules/spring-cloud-config/spring-cloud-config-overriding-properties-server/src/main/resources/config/application.properties b/spring-cloud-modules/spring-cloud-config/spring-cloud-config-overriding-properties-server/src/main/resources/config/application.properties new file mode 100644 index 0000000000..0feac5bb17 --- /dev/null +++ b/spring-cloud-modules/spring-cloud-config/spring-cloud-config-overriding-properties-server/src/main/resources/config/application.properties @@ -0,0 +1 @@ +shared-property=This property is shared accross all client applications diff --git a/spring-cloud-modules/spring-cloud-config/spring-cloud-config-overriding-properties-server/src/main/resources/config/baeldung.properties b/spring-cloud-modules/spring-cloud-config/spring-cloud-config-overriding-properties-server/src/main/resources/config/baeldung.properties new file mode 100644 index 0000000000..471331b8bb --- /dev/null +++ b/spring-cloud-modules/spring-cloud-config/spring-cloud-config-overriding-properties-server/src/main/resources/config/baeldung.properties @@ -0,0 +1,2 @@ +hello=${app.hello:Hello Jane Doe!} +welcome=Welcome Jane Doe! diff --git a/spring-cloud-modules/spring-cloud-config/spring-cloud-config-overriding-properties-server/src/test/java/com/baeldung/spring/cloud/config/server/SpringContextTest.java b/spring-cloud-modules/spring-cloud-config/spring-cloud-config-overriding-properties-server/src/test/java/com/baeldung/spring/cloud/config/server/SpringContextTest.java new file mode 100644 index 0000000000..bfa7e3639c --- /dev/null +++ b/spring-cloud-modules/spring-cloud-config/spring-cloud-config-overriding-properties-server/src/test/java/com/baeldung/spring/cloud/config/server/SpringContextTest.java @@ -0,0 +1,19 @@ +package com.baeldung.spring.cloud.config.server; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +import com.baeldung.spring.cloud.config.overridingproperties.ConfigServer; + +@ExtendWith(SpringExtension.class) +@SpringBootTest(classes = ConfigServer.class) +@ActiveProfiles("native") +public class SpringContextTest { + + @Test + public void whenSpringContextIsBootstrapped_thenNoExceptions() { + } +} diff --git a/spring-cloud-modules/spring-cloud-config/spring-cloud-config-overriding-properties-server/src/test/resources/application.properties b/spring-cloud-modules/spring-cloud-config/spring-cloud-config-overriding-properties-server/src/test/resources/application.properties new file mode 100644 index 0000000000..ded1724100 --- /dev/null +++ b/spring-cloud-modules/spring-cloud-config/spring-cloud-config-overriding-properties-server/src/test/resources/application.properties @@ -0,0 +1 @@ +spring.cloud.config.server.native.search-locations=classpath:/config