SpringCloudConfig When I use these annotations @RefreshScope @ConfigurationProperties ,I was in trouble

2.2k Views Asked by At

SpringCloudConfig trouble

When I use these annotations @RefreshScope @ConfigurationProperties, I was in trouble.

@Component
@RefreshScope
@ConfigurationProperties(prefix = "config.message")
public class MessageProperties {
    private int max_num;
    private boolean begin;
    private String ding_department;  

    // getter, setter...
}

like this ! Config does not work;
but when I use only @ConfigurationProperties,it works. So What's the use of @RefreshScope. And how to fix it?

1

There are 1 best solutions below

0
On

So when you use "I was in trouble" in stackoveflow you are in trouble that there is high probability no one to answer.

@ConfigurationProperties is used for mapping properties to a POJO, with prefix you start using hierarchical properties structure. SO for example based on your description your code will work if you have the following .yml

config:
    message:
      max_num:
      begin:
      ding_department:

If for example you use spring-cloud-config server to store the configuration properties and spring-boot and want on change on the file the corresponding Bean with injected conf file to be update you add @RefreshScope, but even if you do this the bean is not updated you have to call the /refresh url or to trigger event which will refresh it.