BAEL-5285-spring-cloud-overriding-remote-properties (#13000)

* BAEL-5285-spring-cloud-overriding-remote-properties
* BAEL-5285- Adding missing endpoint for the shared property.
https://jira.baeldung.com/browse/BAEL-5285
This commit is contained in:
Christian German 2022-11-23 18:55:45 +01:00 committed by GitHub
parent 21c735364e
commit ee19bc0f34
14 changed files with 180 additions and 1 deletions

View File

@ -18,6 +18,8 @@
<modules>
<module>spring-cloud-config-server</module>
<module>spring-cloud-config-client</module>
<module>spring-cloud-config-overriding-properties-client</module>
<module>spring-cloud-config-overriding-properties-server</module>
</modules>
<dependencyManagement>
@ -36,4 +38,4 @@
<spring-cloud-dependencies.version>2021.0.3</spring-cloud-dependencies.version>
</properties>
</project>
</project>

View File

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-cloud-config-overriding-properties-client</artifactId>
<name>spring-cloud-config-overriding-properties-client</name>
<parent>
<groupId>com.baeldung.spring.cloud</groupId>
<artifactId>spring-cloud-config</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

View File

@ -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);
}
}

View File

@ -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;
}
}

View File

@ -0,0 +1,3 @@
spring.cloud.config.name=baeldung
spring.config.import=optional:configserver:http://localhost:8081
app.hello=Hello, overriden local property!

View File

@ -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() {
}
}

View File

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-cloud-config-overriding-properties-server</artifactId>
<name>spring-cloud-config-overriding-properties-server</name>
<parent>
<groupId>com.baeldung.spring.cloud</groupId>
<artifactId>spring-cloud-config</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

View File

@ -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);
}
}

View File

@ -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!

View File

@ -0,0 +1 @@
shared-property=This property is shared accross all client applications

View File

@ -0,0 +1,2 @@
hello=${app.hello:Hello Jane Doe!}
welcome=Welcome Jane Doe!

View File

@ -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() {
}
}

View File

@ -0,0 +1 @@
spring.cloud.config.server.native.search-locations=classpath:/config