@RefreshScope not working - Spring Boot

后端 未结 2 1632
花落未央
花落未央 2020-12-28 11:04

I am following the approach described here: https://github.com/jeroenbellen/blog-manage-and-reload-spring-properties, the only difference is that in my case, the properties

相关标签:
2条回答
  • 2020-12-28 11:22

    Try using @ConfigurationProperties instead. e.g.

    @ConfigurationProperties(prefix="config")
    public class CloudConfig {
    
        private Integer count;
    
        public Integer count() {
            return this.count;
        }
    
        public void setCount(Integer count) {
            this.count = count;
        }
    
    }
    

    The reference doc from spring cloud states:

    @RefreshScope works (technically) on an @Configuration class, but it might lead to surprising behaviour: e.g. it does not mean that all the @Beans defined in that class are themselves @RefreshScope. Specifically, anything that depends on those beans cannot rely on them being updated when a refresh is initiated, unless it is itself in @RefreshScope (in which it will be rebuilt on a refresh and its dependencies re-injected, at which point they will be re-initialized from the refreshed @Configuration).

    0 讨论(0)
  • 2020-12-28 11:31

    Anyone else facing this issue, please make sure the followings:

    1. Your controller is annotated with @RefreshScope
    2. Spring boot actuator is added into your dependency, as it is the module which actually provides these endpoints:

      org.springframework.boot spring-boot-starter-actuator

    3. Refresh endpoint has been updated to:

      http://{ip_address}:{port}/actuator/refresh

    4. Refresh endpoint isn't enabled by default. You have to enable it explicitly in the bootstrap.properties file by adding the following line:

      management.endpoints.web.exposure.include=*

    I have enabled all the endpoints, while you can just enable the specific endpoints as well.

    0 讨论(0)
提交回复
热议问题