Search code examples
springspring-bootspring-cloudspring-cloud-config

RefreshScope Runtime Configuration Without Spring Cloud Config Server


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?


Solution

  • 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>