I want to achieve the following:
- when in 'dev' mode, embbed Spring Cloud Config in the current webapp
- when not in 'dev' mode, connect to the Spring Cloud Config server instance which is already running
Thus my classpath for the current webapp contains dependencies to 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, it's OK (embedded config server is configured and launched)
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
When not in 'dev' mode (spring.profiles.active = prod for instance), the current webapp does not start: it cannot autowire my properties (I guess the embedded server is launched with bad configuration)
If I comment the spring-cloud-config-server dependency in the POM, then it works.
I thougth 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 could I do (without using maven profile)? Is there a simple way to disable spring cloud config server? Is there a better way to achieve my goal?
Any help appreciated.
P.S. 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
Please see a 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 launch the Client class from the client-app module, all is OK (embedded mode is on => see dev profile in bootstrap.yml)
Then, launch config-server (ConfigServer class). Then change 'spring.profiles.active' for 'prod' (or whatever) in the client-app and restart it: the property injection does not work anymore (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 dependencies : spring-cloud-config-server from the client-app module, it works again.
Hope it is more clear now. Thanks,
According to this class in spring cloud config server: Config server disables config client explicitly unless you set
spring.cloud.config.enabled=true
from a System Property (-D
) or viaSpringApplicationBuilder
. That is the only way to get this to work currently. You are welcome to submit an enhancement request explaining your use case.