Skip to main content
added 134 characters in body
Source Link
Dovmo
  • 8.8k
  • 3
  • 33
  • 46

Can you just use the Spring Cloud Config "Server" and have it signal to your Spring Cloud client that the properties file changed. See this example:

https://spring.io/guides/gs/centralized-configuration/

Under the covers, it is doing a poll of the underlying resource and then broadcasts it to your client:

 @Scheduled(fixedRateString = "${spring.cloud.config.server.monitor.fixedDelay:5000}") public void poll() { for (File file : filesFromEvents()) { this.endpoint.notifyByPath(new HttpHeaders(), Collections .<String, Object>singletonMap("path", file.getAbsolutePath())); } } 

If you don't want to use the config server, in your own code, you could use a similar scheduled annotation and monitor your properties file:

@Component public class MyRefresher { @Autowired private ContextRefresher contextRefresher; @Scheduled(fixedDelay=5000) public void myRefresher() { // Code here could potentially look at the properties file // to see if it changed, and conditionally call the next line... contextRefresher.refresh(); } } 

Can you just use the Spring Cloud Config "Server" and have it signal to your Spring Cloud client that the properties file changed. See this example:

https://spring.io/guides/gs/centralized-configuration/

Under the covers, it is doing a poll of the underlying resource and then broadcasts it to your client:

 @Scheduled(fixedRateString = "${spring.cloud.config.server.monitor.fixedDelay:5000}") public void poll() { for (File file : filesFromEvents()) { this.endpoint.notifyByPath(new HttpHeaders(), Collections .<String, Object>singletonMap("path", file.getAbsolutePath())); } } 

If you don't want to use the config server, in your own code, you could use a similar scheduled annotation and monitor your properties file:

@Component public class MyRefresher { @Autowired private ContextRefresher contextRefresher; @Scheduled(fixedDelay=5000) public void myRefresher() { contextRefresher.refresh(); } } 

Can you just use the Spring Cloud Config "Server" and have it signal to your Spring Cloud client that the properties file changed. See this example:

https://spring.io/guides/gs/centralized-configuration/

Under the covers, it is doing a poll of the underlying resource and then broadcasts it to your client:

 @Scheduled(fixedRateString = "${spring.cloud.config.server.monitor.fixedDelay:5000}") public void poll() { for (File file : filesFromEvents()) { this.endpoint.notifyByPath(new HttpHeaders(), Collections .<String, Object>singletonMap("path", file.getAbsolutePath())); } } 

If you don't want to use the config server, in your own code, you could use a similar scheduled annotation and monitor your properties file:

@Component public class MyRefresher { @Autowired private ContextRefresher contextRefresher; @Scheduled(fixedDelay=5000) public void myRefresher() { // Code here could potentially look at the properties file // to see if it changed, and conditionally call the next line... contextRefresher.refresh(); } } 
Source Link
Dovmo
  • 8.8k
  • 3
  • 33
  • 46

Can you just use the Spring Cloud Config "Server" and have it signal to your Spring Cloud client that the properties file changed. See this example:

https://spring.io/guides/gs/centralized-configuration/

Under the covers, it is doing a poll of the underlying resource and then broadcasts it to your client:

 @Scheduled(fixedRateString = "${spring.cloud.config.server.monitor.fixedDelay:5000}") public void poll() { for (File file : filesFromEvents()) { this.endpoint.notifyByPath(new HttpHeaders(), Collections .<String, Object>singletonMap("path", file.getAbsolutePath())); } } 

If you don't want to use the config server, in your own code, you could use a similar scheduled annotation and monitor your properties file:

@Component public class MyRefresher { @Autowired private ContextRefresher contextRefresher; @Scheduled(fixedDelay=5000) public void myRefresher() { contextRefresher.refresh(); } }