SHM
SHM

Reputation: 194

Listening to context Refreshed in Spring cloud consul config

Spring cloud consul config allows dynamic refresh of properties whenever the property is changed in consul. Is there a way to listen whenever the change happens?

@Component
public class ContextRefreshListener {

@EventListener
public void handleContextRefresh(ContextRefreshedEvent event) {
    System.out.println("refreshed");
}

@EventListener
public void handleContextStart(ContextStartedEvent event) {
    System.out.println("started");
}


@EventListener
public void handleContextRefresh(ApplicationContextEvent event) {
    System.out.println("context");
}

}

I tried the above three events, but no luck. Is there any way to do listen to events whenever the refresh happens?

Upvotes: 1

Views: 1555

Answers (2)

RefreshScopeRefreshedEvent is better.

Upvotes: 0

SHM
SHM

Reputation: 194

I was able to do it by following way

@EventListener
public void handleContextStart(EnvironmentChangeEvent event) {
    System.out.println("changed");
    //Use this for getting the version from consul

}

Upvotes: 1

Related Questions