Share configuration between Spring cloud configuration clients

I am trying to split the configuration between Spring cloud clients with a Spring cloud configuration server that has a file repository:

@Configuration @EnableAutoConfiguration @EnableConfigServer public class ConfigServerApplication { public static void main(String[] args) { SpringApplication.run(ConfigServerApplication.class, args); } } // application.yml server: port: 8888 spring: profiles: active: native test: foo: world 

One of my Spring Cloud clients uses the test.foo configuration defined on the configuration server and it is configured as shown below:

 @SpringBootApplication @RestController public class HelloWorldServiceApplication { @Value("${test.foo}") private String foo; @RequestMapping(path = "/", method = RequestMethod.GET) @ResponseBody public String helloWorld() { return "Hello " + this.foo; } public static void main(String[] args) { SpringApplication.run(HelloWorldServiceApplication.class, args); } } // boostrap.yml spring: cloud: config: uri: ${SPRING_CONFIG_URI:http://localhost:8888} fail-fast: true // application.yml spring: application: name: hello-world-service 

Despite this configuration, the Environment in the Spring Cloud Client does not contain a test.foo entry (cf java.lang.IllegalArgumentException: Could not resolve placeholder 'test.foo' )

However, it works fine if I put the properties in the hello-world-service.yml file in my file repository in the configuration file.

Maven dependencies on Spring Cloud Brixton.M5 and Spring Download 1.3.3.RELEASE with spring-cloud-starter-config and spring-cloud-config-server

+5
source share
1 answer

From Spring Cloud Documentation

With a "native" profile (local file system), it is recommended that you use an explicit search location that is not part of the server’s own configuration. Otherwise, the application * resources in the search locations are deleted by default, because they are part of the server.

So, I have to put the general configuration in an external directory and add the path to the application.yml config-server file.

 // application.yml spring: profiles: active: native cloud: config: server: native: search-locations: file:/Users/herau/config-repo // /Users/herau/config-repo/application.yml test: foo: world 
+1
source

Source: https://habr.com/ru/post/1244302/


All Articles