2

Is it possible to refresh the configurations calling a java method instead to use the REST api:

curl localhost:8080/actuator/refresh -d {} -H "Content-Type: application/json"

Fabry
  • 1,498
  • 4
  • 23
  • 47

1 Answers1

2

You can use the ResartEndpoint class from spring-cloud-context:

@Autowired
private RestartEndpoint restartEndpoint;

...

Thread restartThread = new Thread(() -> restartEndpoint.restart());
restartThread.setDaemon(false);
restartThread.start();

This is how @alexbt suggests to do it. But note that the spring cloud documentation also says you can refresh individual beans provided they are RefreshScope.

Ryan Dawson
  • 11,832
  • 5
  • 38
  • 61
  • Thanks. Just a question, there is a reason why you use the restartEndpoint in a thread? – Fabry Oct 16 '18 at 07:06
  • It makes sense to invoke it asynchronously (https://stackoverflow.com/a/47634569/9705485) but I'm not sure you need to do this anymore as it seems to have been added to the underlying code in v2 - https://github.com/spring-cloud/spring-cloud-commons/commit/f7519a30ad0a02b63a113ff66621bf6c6991d251#diff-344ead166eff93b62c827e6f8ff1caed – Ryan Dawson Oct 16 '18 at 09:13