其他分享
首页 > 其他分享> > 没有Spring Cloud Config Server的RefreshScope运行时配置

没有Spring Cloud Config Server的RefreshScope运行时配置

作者:互联网

是否可以使用@RefreshScope通过POST rest api / refresh调用刷新property(api-url),而无需设置spring cloud配置服务器和spring cloud配置客户端.

例如Consumer.java

@Service
public class Consumer {

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

现在正在从application.yml中读取api-url.我想在运行时更改api-url而不重启服务器.

春季靴子有可能吗?

解决方法:

是的,只包括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,spring,spring-boot,spring-cloud
来源: https://codeday.me/bug/20191013/1909702.html