This article mainly introduces you to the relevant information about the config modification configuration of the spring cloud learning tutorial. The article introduces it in detail through the example code. It has certain reference learning value for everyone's study or work. Friends who need it Let’s learn with the editor below.
We have talked about the config configuration of spring cloud before, so how to make the configuration take effect on the client after modifying the configuration on the Git side? Let’s take a look at the detailed introduction below.
Access interface modification
refresh
Execute in post mode http:// localhost/refresh will refresh the configuration in env
restart
If the configuration information has been injected into the bean, since the bean is a singleton, The modified configuration will not be loaded
needs to be executed through post method http://localhost/restart,
needs to be executed through application.properties
Configuration in endpoints.restart.enabled=true
Start the specified port
Disadvantages: It takes a long time to restart, so there is RefreshScope
RefreshScope
##
package com.lkl.springcloud.config.client; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.cloud.context.config.annotation.RefreshScope; import org.springframework.context.annotation.ComponentScan; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; /** * Created by liaokailin on 16/4/28. */ @EnableAutoConfiguration @ComponentScan @RestController @RefreshScope public class Application { @Value("${name:World!}") String name ; @RequestMapping("/") public String home(){ return "Hello " + name; } public static void main(String[] args) { SpringApplication.run(Application.class,args); } }
The above is the detailed content of Spring cloud tutorial config modification configuration method introduction. For more information, please follow other related articles on the PHP Chinese website!