Use Spring Cloud Bus and Spring Cloud Config Server Together
Firstly, you can follow these instructions for Spring Cloud Server:
Add these to your dependencies as an extra for Spring Cloud Bus:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-monitor</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-kafka</artifactId>
</dependency>
If you would like to inspect which dependencies in “spring-cloud-starter-bus-kafka”, these are the dependencies in version 3.0.3 (Here, I use a plugin called Maven Helper in IntelliJ to use “Dependency Analyzer” view in pom.xml file).
So, if you are already using “spring-kafka” as a dependency, you can remove it.
To be able to post our refresh command, you should add these properties to your config server’s application.properties:
spring.cloud.bus.enabled=true
management.endpoints.web.exposure.include=busrefresh
You can see allowed Actuator endpoints in IntelliJ ‘s related tab:
This is your cURL request (if you are using port no 8888 for your config server project):
curl -L -X POST 'http://localhost:8888/actuator/busrefresh'
After the POST request, go to your main project’s logs and see which keys are refreshed:
Voilà!
You can visit my Microservices project (implemented with Spring Cloud) GitHub url for sample code:
Happy Coding!