java - Spring 配置@RefreshScope

标签 java spring spring-boot microservices spring-cloud

我能否仅在云配置服务器中使用 @RefreshScope(连同属性上的 @Value),或者我是否也可以在没有配置服务器的情况下使用?我正在尝试在没有配置服务器的情况下使用它。我试图通过更改 .property 文件中的值并尝试再次请求来获取 @Value 属性,我会得到更新的值吗?那可能吗?

最佳答案

不,您应该将它与配置服务器一起使用,否则您将无法即时读取更新属性。关注this article看看this如果您在动态加载更新的属性时遇到任何问题。

In theory, you could refresh the application context, but I wouldn't recommend this. Spring Cloud has provided an annotation to mark a bean as refreshable. By adding spring actuator, we can refresh those beans on the fly.

关于java - Spring 配置@RefreshScope,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53559009/

相关文章:

java - Android - 测量两次按钮点击之间的时间

java - jar 文件与黑莓不兼容

spring - TOMEE + Spring + JAX-RS (NoSuchMethodError) jar 冲突

java - 如何从java中的过程中获取值

java - 了解 Spring 的身份验证对象及其创建的上下文

java - 正则表达式不适用于替换特殊字符

java - Spring Boot 2.2.0 中的两个数据源、两个存储库

spring - 为什么秒 :authentication ="name" show all user information?

java - Spring-boot - 参数化测试 - 访问MethodSource中的Application.properties

java - 如何解析包含 Javascript 的网页?