RefreshScope Runtime Configuration Without Spring Cloud Config Server

女生的网名这么多〃 提交于 2019-12-31 04:15:09

问题


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.

for.e.g Consumer.java

@Service
public class Consumer {

@value(${api-url})
private String apiUrl;

api-url is getting read from application.yml now. I want to change the api-url at runtime without restarting server.

Is it possible in spring boot?


回答1:


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>


来源:https://stackoverflow.com/questions/43737305/refreshscope-runtime-configuration-without-spring-cloud-config-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!