没有 Spring Cloud Config Server 的 RefreshScope 运行时配置 [英] RefreshScope Runtime Configuration Without Spring Cloud Config Server
本文介绍了没有 Spring Cloud Config Server 的 RefreshScope 运行时配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以使用@RefreshScope 通过 POST rest api/refresh 调用刷新属性(api-url),而无需设置 spring cloud 配置服务器和 spring cloud 配置客户端设置.
Is it possible to refresh property(api-url) through POST rest api /refresh call using @RefreshScope without having setup of spring cloud config server and spring cloud config client setup.
例如 Consumer.java
for.e.g Consumer.java
@Service
public class Consumer {
@value(${api-url})
private String apiUrl;
api-url 现在正在从 application.yml 读取.我想在不重启服务器的情况下在运行时更改 api-url.
api-url is getting read from application.yml now. I want to change the api-url at runtime without restarting server.
spring boot 可以吗?
Is it possible in spring boot?
推荐答案
是的,只包含 spring cloud starter
Yes, just include spring cloud starter
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.RELEASE</version>
</parent>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Dalston.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter</artifactId>
</dependency>
</dependencies>
这篇关于没有 Spring Cloud Config Server 的 RefreshScope 运行时配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文