Ankit Bansal
Ankit Bansal

Reputation: 2348

Spring Boot Config at Git

I am following an blog :

https://github.com/jeroenbellen/blog-manage-and-reload-spring-properties

I am developing the services using spring boot and I want to change the config at run-time without application restart.

I have run the code mentioned in the above github repo. What I am not able to understand how does the example-service knows about config-service. There is nothing in code which link them together.

Also, there is just one example service but I have 10s of such example service, how do I use just one config service for all example services

Upvotes: 2

Views: 1531

Answers (2)

Issam El-atif
Issam El-atif

Reputation: 2486

First question

how does the example-service knows about config-service?

Short answer

Magic happen when you add spring-cloud-config-client dependency

Long answer from spring cloud documentation

Client Side Usage

To use these features in an application, just build it as a Spring Boot application that depends on spring-cloud-config-client (e.g. see the test cases for the config-client, or the sample app). The most convenient way to add the dependency is via a Spring Boot starter org.springframework.cloud:spring-cloud-starter-config. There is also a parent pom and BOM (spring-cloud-starter-parent) for Maven users and a Spring IO version management properties file for Gradle and Spring CLI users.


Second question

Also, there is just one example service but I have 10s of such example service, how do I use just one config service for all example services

You just have to add spring-cloud-config-client dependency to each service. All services will look for config-service on http://localhost:8888 8888 being the default port

Upvotes: 1

C-Otto
C-Otto

Reputation: 5843

The default is http://localhost:8888 which is enough for this example, but might differ from your needs in a productive environment :)

You can configure the config server URI in bootstrap.yml (or bootstrap.properties) using the key spring.cloud.config.uri.

The bootstrap configuration file is evaluated first, so that you can set the actual properties using the config server.

Documentation: https://cloud.spring.io/spring-cloud-config/spring-cloud-config.html#config-first-bootstrap

Upvotes: 1

Related Questions