17

I have tried to implement spring external configurations using Config Server. It is working fine for the very first time when the application is started but any changes to the properties file are not being reflected. I tried to use /refresh endpoint to refresh my properties on the fly but it doesn't seem to be working. Any help on this would be greatly helpful.

I tried POSTing to localhost:8080/refresh but getting a 404 Error response.

Below is the code of my application class

   @SpringBootApplication
public class Config1Application {

    public static void main(String[] args) {
        SpringApplication.run(Config1Application.class, args);
    }
}

@RestController
@RefreshScope
class MessageRestController {

    @Value("${message:Hello default}")
    private String message;

    @RequestMapping("/message")
    String getMessage() {
        return this.message;
    }
}

and POM file is

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.0.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <spring-cloud.version>Finchley.M8</spring-cloud.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

    <repositories>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>

and bootstrap.properties

spring.application.name=xxx
spring.cloud.config.uri=https://xxxxxx.com
management.security.enabled=false
endpoints.actuator.enabled=true
ASD
  • 325
  • 1
  • 2
  • 9

5 Answers5

32

The endpoint is now /actuator/refresh for Spring 2 and greater

From the comments:

  • You do need to have the management.endpoints.web.exposure.include=refresh set in the bootstrap.properties/bootstrap.yml

Note: If you're new to Spring-Cloud and not quite sure of what all keywords can go in web.exposure you can set it to * (management.endpoints.web.exposure.include=*) to have all exposed and you can get to know the endpoints and their restrictions later.

iam.Carrot
  • 4,976
  • 2
  • 24
  • 71
spencergibb
  • 24,471
  • 6
  • 69
  • 75
  • Thanks spencergibb. Even the above mentioned end point did not work earlier. I have updated the spring-cloud-dependencies version to Edgware.RELEASE and spring-boot-starter-parent to 1.5.10.RELEASE and it started working. Guess the issue was due to the versions. – ASD Mar 19 '18 at 23:59
  • 6
    No. You need set management.endpoints.web.exposure.include=* (or a list of endpoints to enable) – spencergibb Mar 20 '18 at 00:15
  • Thank you, it worked. I have reverted the versions to the latest and added the above property. Now I am able to see the latest values using above endpoint. – ASD Mar 20 '18 at 01:18
  • 4
    `management.endpoints.web.exposure.include=refresh` would work too. – Shanu Gupta May 21 '18 at 03:05
  • if my app has 100 instances in the cloud, do I need to actually make a GET call to all 100 /actuator/refresh? – Kalpesh Soni Dec 19 '18 at 19:03
  • 4
    @KalpeshSoni that is what spring cloud bus is for. – spencergibb Dec 19 '18 at 23:36
  • @spencergibb So we have few beans with refershscope and consul `ConfigWatch`. Every time we change the key value it is refreshing the key values and also other beans which we dont need to refresh. Is there a way to only refersh key value and not other beans ? Thanks – s7vr Mar 18 '20 at 15:32
  • 2
    @user2683814 not currently. I'd remove `@RefreshScope` and listen for the application event `EnvironmentChangeEvent`, see if the keys you want are there and deal with the changes manually. – spencergibb Mar 18 '20 at 20:11
  • @spencergibb, 3+ years later, is there now a way to only refresh what is needed(I am using `Spring Boot 2.7.x`)? Thank you. – jumping_monkey Jun 27 '23 at 00:29
  • Not sure what you're asking @jumping_monkey and if it's related to this question – spencergibb Jun 27 '23 at 19:51
  • No worries @spencergibb, found my answer. Thanks for replying and being there for the community(as always). Cheers mate. – jumping_monkey Jun 28 '23 at 00:14
4

It worked for me after adding the property

management.endpoints.web.exposure.include=*

In bootstrap.properties and changing the url to /actuator/refresh for spring version above 2.0.0 For spring version 1.0.5 url is /refresh.

svarog
  • 9,477
  • 4
  • 61
  • 77
Rohit Nair
  • 41
  • 3
4

For YAML files, the property's value needs to be wrapped inside double quotes :

# Spring Boot Actuator
management:
  endpoints:
    web:
      exposure:
        include: "*"

Note : Ensure you use the right endpoints keyword (with 's') for this property as long as it exists for another property without 's' : "management.endpoint.health.... " .

Omar
  • 1,430
  • 1
  • 14
  • 31
0

Note: - It's a POST request (not GET)

I've posted the solution here

[https://stackoverflow.com/a/74465108/2171938][1]

-1

If you have issues with accepting formurlencoded in SPRING 2.0>, use :

curl -H "Content-Type: application/json" -d {} http://localhost:port/actuator/refresh

instead of:

curl -d {} http://localhost:port/refresh

which was accepted in SPRING 1.*

Roland Roos
  • 1,003
  • 10
  • 4