download:高级前端进阶必修:自主打造高扩大的业务组件库

Spring Cloud整合 Part 2: 配置核心
Spring Cloud提供了一个对立的配置核心,使得开发人员可能将应用程序的配置集中管理。本文将介绍如何应用Spring Cloud进行配置核心。

配置核心服务器
要应用Spring Cloud的配置核心性能,咱们须要首先启动一个配置核心服务器。以下是示例:

java
@SpringBootApplication
@EnableConfigServer
public class ConfigServerApplication {

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

}
在应用程序的application.properties或application.yml文件中,咱们须要配置Git仓库的地位:

spring.cloud.config.server.git.uri=https://github.com/myorg/myconfig.git
配置客户端
一旦咱们启动了配置核心服务器,咱们就能够应用Spring Cloud的配置客户端性能来拉取应用程序的配置。以下是示例:

java
@RestController
@RequestMapping("/config")
@RefreshScope
public class ConfigController {

@Value("${my.property}")private String myProperty;@GetMappingpublic String getProperty() {    return myProperty;}

}
``