清爽的弹簧靴属性

时间:2014-11-03 15:16:53

标签: spring spring-boot spring-integration

我有一个Spring集成Web应用程序,可以导入一堆属性文件,如下所示:

<context:property-placeholder location="classpath*:*.properties" />

现在我将它转换为spring启动应用程序,我正在使用config类中的@PropertySource导入属性。我也在查看spring cloud配置服务器以获取未来的州项目。所以我的问题是,当属性文件更改时需要刷新的所有bean都需要@RefreshScope,但此时我所知道的xml中没有等效属性。我以为我可以使用scope =&#34; refresh&#34;应用程序抛出错误说&#34;刷新&#34;不是有效的范围。那么当属性文件发生变化时,如何管理刷新xml定义的bean。

我想我可以尝试捕获事件,然后执行context.refresh();但他们是一个更好的方法来做到这已经建立在春天?

1 个答案:

答案 0 :(得分:1)

要注册自定义Scope,您需要声明一个bean定义。如果您使用@EnableAutoConfiguration,Spring Cloud Config会为您执行此操作。如果不这样做,则需要手动创建它(XML或非XML)。 E.g。

@Bean
public static RefreshScope refreshScope() {
    return new RefreshScope();
}

(链接:https://github.com/spring-cloud/spring-cloud-config/blob/1.0.0.M2/spring-cloud-config-client/src/main/java/org/springframework/cloud/autoconfigure/RefreshAutoConfiguration.java#L63

相关问题