spring cloud tutorial config modification configuration details

  • 2020-10-23 20:06:41
  • OfStack

We talked about spring cloud's config configuration before, how to make the Git client take effect after modifying the configuration on the Git side? Let's start with 1 to see the details.

Access interface modification

refresh

post execution of http://localhost/refresh refreshes the configuration in env

restart

If configuration information has been injected into bean, the modified configuration will not be loaded since bean is singleton

It is necessary to execute http://localhost/restart by post.

Need to pass through application.properties In the configuration endpoints.restart.enabled=true Starts the specified port

Cons: It takes a long time to get through restart, hence 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 variable values in bean are refreshed when refresh is executed.

ok ~ it's work ! more about is here (also downloadable locally)

conclusion


Related articles: