@RefreshScope not working. Properties are not updated after being modified the second time in Consul

Viewed 1345

I am working with Consul using spring-cloud-consul and currently have this problem. I create a key in consul as config/ConsulServer/my/username with value as "bob". In my controller, i return this value if a API call "/foo" is made. When i modified it the first time to "steve" the value is updated and i get "steve". However, it does not work the second time. The value is still "steve". Could anyone please help on what I did wrong ? My codes are

@SpringBootApplication
@EnableDiscoveryClient
public class ConsulServer {
  public static void main(String[] args) {
    SpringApplication.run(ConsulServer.class, args);
  }
}

@Component
@RefreshScope
@ConfigurationProperties("my")
public class SampleProperties {
   private String username;
   public String getUsername() {
    return username;
   }
   public void setUsername(String username) {
    this.username= username;
   }
}

@RestController
public class ConsulController {
    @Autowired
    private SampleProperties consulConfig;

    @GetMapping("/foo")
    public String prop() {
       return this.consulConfig.getUsername();
    }
}

My bootstrap.yml is

spring:
  application:
     name: ConsulServer
  cloud:
     consul:
     host: localhost
     port: 8500
     config:
        enabled: true
        fail-fast: true
        watch:
          enabled: true
     discovery:
        register: true

My application.yml is

spring:
  application:
     name: ConsulServer

I am using spring-cloud-starter-consul-all version 2.1.0.RC3

0 Answers
Related