Refresh client configuration content manually (spring cloud config)


Refresh client configuration content manually

Add dependency to client project


Client project modification profile

Add management. Endpoints. Web. Exposure. Include = refresh, health, info
#Settings do not need to be registered in consumer
#Exposed access points shown

Client program adds support for refreshing annotation

Add @ refreshscope annotation on the class using configuration center:

//Refresh trigger address / Actor / refresh
public class ConfigTestController {

    //Configuration information is read by @ value annotation, and configuration items are read by ${configuration items}
    private String configBluersw;

    public String ConfigTest(){
        return this.configBluersw;

Test refresh effect

Change the configuration content in Git warehouse to Test-5 (bluersw. Config = Test-5), start the client program (spring cloud config client), refresh the client page / configtest, find out whether the display content is Test-3, and then execute:

curl -X POST

Refresh the page again. The content of the page is displayed as Test-5, indicating that the configuration information in the client program has read the latest value.