0

I am using spring-cloud-starter for refreshing the beans when there is a config change. It works as expected for beans that I have control over. If there are certain beans that belong to an external jar and I want them to be refreshed as well when there is a config change, is it possible to do that? This is more relevant for AutoConfiguration beans that gets created using configs but might not have @RefreshScope annotated.

Sachin Jain
  • 97
  • 1
  • 10

1 Answers1

0

@RefreshScope is not the only indicator that a bean has to be reinitialized upon the environment change event. There's also @ConfigurationProperties - any beans that were bound to environment via this annotation will also be refreshed.

If neither is applicable to your case and still for some reason you'd like to refresh external beans, you can do this explicitly by creating an EnvironmentChangeEvent event listener that destroys and initializes the beans you need. For an example of this take a look at org.springframework.cloud.context.properties.ConfigurationPropertiesRebinder from spring-cloud-context module.

dekkard
  • 6,121
  • 1
  • 16
  • 26