Disable Spring Cloud Server Configuration using Profile?
I want to achieve the following:
- when in 'dev' mode, inject Spring Cloud Config into the current web folder
- if not in "dev" mode, connect to the Spring Cloud Config server instance that is already running
So mypathpath for the current webapp contains dependencies for the config server and client:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
In dev mode and with the following properties in bootstrap.yml, that's ok (the built-in config server is up and running)
spring:
application:
name: app1
profiles:
active: dev
cloud:
config:
uri: ${SPRING_CONFIG_URI:http://localhost:8888}
---
spring:
profiles: dev
cloud:
config:
server:
bootstrap: true
git:
uri: https://github.com/nocquidant/my-config-repo.git
basedir: target/config
If not in 'dev' mode (spring.profiles.active = prod for example), the current Webapp does not start: it cannot autodetect my properties (I think the embedded server started with bad configuration)
If I comment out the spring-cloud-config-server dependency in the POM, then it works.
I could achieve what I want using the following, but no (actually using EnableConfigServer or not doesn't seem to change anything):
@Configuration
@Profile("dev")
@EnableConfigServer
public static class EmbeddedConfigServer { }
How can I (without using maven profile)? Is there an easy way to disable Spring's cloud config server? Is there a better way to achieve my goal?
Any help was appreciated.
PS version used:
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-parent</artifactId>
<version>1.0.3.BUILD-SNAPSHOT</version>
</parent>
//Nick
// --- Edit # 1
See simple project on github: https://github.com/nocquidant/exchange/tree/master/poc-spring-cloud/
It contains 2 simple modules: config-server and client-app.
First, if you run the Client class from the client-application module everything is fine (inline mode enabled => see dev profile in bootstrap.yml)
Then run config-server (ConfigServer class). Then change 'spring.profiles.active' to 'prod' (or whatever) in the client application and restart it: property injection no longer works (and the webapp refuses to start).
Caused by: org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 1 errors
Field error in object 'server' on field 'port': rejected value [${taap.bak.config.port}];
Thus, it cannot connect to the config-server module. And if you comment the maven: spring-cloud-config-server dependencies from the client-application module, it works again.
Hopefully this is clearer now. Thank,
According to this class in spring cloud config server: Config server disables the config client explicitly unless you set spring.cloud.config.enabled=true
Property ( -D
) from the system or via SpringApplicationBuilder
. This is the only way to get this to work at the moment. You can submit an improvement request explaining your use case.