I'm trying to share configuration between Spring Cloud clients with a Spring Cloud config server which have a file-based 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 client use the test.foo
configuration, defined in the config server, and it is configured like 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 doesn't contains the test.foo
entry (cf java.lang.IllegalArgumentException: Could not resolve placeholder 'test.foo'
)
However it's works perfectly if i put the properties in a hello-world-service.yml
file, in my config server file-based repository.
Maven dependencies on Spring Cloud Brixton.M5 and Spring Boot 1.3.3.RELEASE with
spring-cloud-starter-config
andspring-cloud-config-server
From Spring Cloud documentation
With the "native" profile (local file system backend) it is recommended that you use an explicit search location that isn’t part of the server’s own configuration. Otherwise the application* resources in the default search locations are removed because they are part of the server.
So i should put the shared configuration in an external directory and add the path in the application.yml
file of the config-server
.
// 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With