动态Spring Cloud配置更改

时间:2019-02-08 10:28:32

标签: spring-cloud-config

我能够使用Spring云配置在git中动态检索application.properties中的更改。

Bean

public class PropertyBean {

      @Value("${refreshscope.test}")
      private String scope;

      @Value("${refreshscope.test1}")
      private String scope1;

      public String getScope() {
       return scope;
      }

      public String getScope1() {
    return scope1;
      }
    }

配置

    @Configuration
    public class AppConfiguration {


    @Bean
        @RefreshScope
        public PropertyBean aBean() {
            return new PropertyBean();
        }

        @Bean
        public RefreshScopeRefreshedListener 
                  remoteApplicationEventListener(PropertyBean aBean) {
              return new RefreshScopeRefreshedListener(aBean);
        }
    }

监听器

    public class RefreshScopeRefreshedListener implements 
                 ApplicationListener<RefreshScopeRefreshedEvent> {

           private PropertyBean aBean;

           public RefreshScopeRefreshedListener(PropertyBean abean) {
           this.aBean = abean;
           }

           @Override
           public void onApplicationEvent(RefreshScopeRefreshedEvent event) 
           {
              System.out.println("RRRfreshed Scop variable1==="+aBean.getScope());
    System.out.println("RRRfreshed Scop variable2==="+aBean.getScope1());


}

}

问题

我们如何知道客户端中的哪些属性已更改?例如,我只更改了一个属性,在git属性文件中说了'refreshscope.test'。我应该知道只在客户端更改了'refreshscope.test'或更改了所有属性的列表。

0 个答案:

没有答案