Home  >  Article  >  Java  >  Spring cloud tutorial config modification configuration method introduction

Spring cloud tutorial config modification configuration method introduction

巴扎黑
巴扎黑Original
2017-09-06 09:42:471814browse

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.propertiesConfiguration in endpoints.restart.enabled=trueStart 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);
 }
}

When executing refresh, the variable value in the bean will be refreshed.

ok ~ it's work ! more about is here (can also be downloaded locally)

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn