You have two choices :
- Through Spring Boot Actuator
- Through Spring Cloud Bus
Option 1 : Through Spring Boot Actuator.
Add the spring-boot-starter-actuator dependency in pom.xml :
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-config</artifactId> </dependency>
When add new changes and you want see that, then you have to call this url :
http://ip:port/actuator/refresh
But the problem is that the refresh happens at individual server.
Option 2 : Through Spring Cloud Bus
But for this you have to use some messaging queue system like Kafka, RabbitMQ and so on.
I will show with RabbitMQ only.
Read here : https://www.rabbitmq.com/tutorials/tutorial-one-spring-amqp.html
Add the spring-boot-starter-amqp & spring-boot-starter-actuator in the pom.xml :
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-amqp</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-config</artifactId> </dependency>
When add new changes and you want see that, then you have to call this url :
http://ip:port/actuator/bus-refresh
Plus Point : The refresh happens on all the servers.
Note: You can use @RefreshScope to auto refresh the @Value renderers. Example :
@Configuration @RefreshScope public class AppConfig { @Value("${some.value}") private String value; @Bean public PropertyPlaceholderConfigurer propertyPlaceholderConfigurer() throws Exception { final ClassPathResource classPathRessource = new ClassPathResource(PROPERTIES_FILE); final Properties fileProperties = loadDbPropertiesFromInputStream(classPathRessource.getInputStream()); // Instantiate properties dataSource final DriverManagerDataSource dataSource = new DriverManagerDataSource(); dataSource.setDriverClassName(fileProperties.getProperty(PROPERTY_KEY_DATABASE_DRIVER)); dataSource.setUrl(fileProperties.getProperty(PROPERTY_KEY_DATABASE_URL)); dataSource.setUsername(fileProperties.getProperty(PROPERTY_KEY_DATABASE_USERNAME)); dataSource.setPassword(fileProperties.getProperty(PROPERTY_KEY_DATABASE_PASSWORD)); // Init PropertyPlaceholderConfigurer final PropertyPlaceholderConfigurer propertyPlaceholderConfigurer = new PropertyPlaceholderConfigurer(); propertyPlaceholderConfigurer.setLocation(classPathRessource); // Add properties from defined database propertyPlaceholderConfigurer.setPropertiesArray(ConfigurationConverter.getProperties(getDatabaseConfiguration(dataSource))); return propertyPlaceholderConfigurer; } }