spring-cloud / spring-cloud-config

External configuration (server and client) for Spring Cloud
Apache License 2.0
1.94k stars 1.28k forks source link

Problems to setup embedded Spring Config Server #2426

Open mibutec opened 1 month ago

mibutec commented 1 month ago

I'm on my way to setup Spring Cloud Config to allow one of our applications to change some configuration properties while runtime. As for now it is only one application to be managed by the Spring Config Server and I want to keep deployment simple, I would like to deploy the Config Server and the Application as one. As far as I got this is supported as "Embedding the Config Server".

To get this running, I used https://spring.io/guides/gs/centralized-configuration as base to setup a separated Config Server and a client. I also setup a config repository in file:/Users/mibutec/projects/config-repo containing

message=Hello, Mibutec

This setup works fine, and when calling curl localhost:8888/message I see my message Hello, Mibutec. Everything fine!

Now I tried to get the Config Server also running within the client application.

I changed the application.properties of the client application as follows:

server.port=8888
spring.application.name=a-bootiful-client
management.endpoints.web.exposure.include=*

# spring.config.import=http://localhost:8888/
spring.profiles.active=composite
spring.cloud.config.server.composite[0].type=git
spring.cloud.config.server.composite[0].uri=file:/Users/mibutec/projects/config-repo
spring.cloud.config.server.bootstrap=true

I enabled the Config Server by adding @EnableConfigServer to the Main-class.

I didn't do anything with some bootstrap.properties, as I goy this is only required Spring Boot < 2.4 and I'm beyond.

However, I don't get the client to update it's properties. Whenever I call localhost:8888/message I see my message Hello default

The Config Server itself seems to work fine: Calling curl localhost:8888/a-bootful-client-composite.yml returns

message: Hello, Mibutec

I also tried to refresh the application via actuator, which also does not change anything.

So my questions:

ryanjbaxter commented 1 hour ago

Because the configuration needs to be fetched during bootstrap in order to configure the config server you need to take the properties that you have in application.properties and put them in bootstrap.properties and include spring-cloud-starter-bootstrap on the application classpath.