spring cloud config
Brief introduction
Provide server and client support Spring Cloud Config configured to externalize distributed system. Use Config Server, you can manage an external application properties in all environments. Concept mapping and Spring Environment and PropertySource abstract on the client and the server, so they are very suitable for Spring applications, but can be used with any application that runs with any language. When the application through the deployment pipeline from development to testing and into production, you can manage the configuration between these environments and ensure that all applications have content that requires a runtime migration. The default storage backend server implementations use git, so it can easily support a label version of the configuration environment, as well as various tools for managing content. Was added to make and use alternative Spring configuration insert them easily.
Spring Cloud Config Server features
用于外部配置的HTTP,基于资源的API(名称 值对或等效的YAML内容)
加密和解密属性值(对称或非对称)
使用可轻松嵌入Spring Boot应用程序
可以轻松的结合Eureka实现高可用
可以轻松的结合Spring Cloud Bus实现自动化持续集成
Config Client Function
绑定到Config Server并Environment使用远程属性源初始化Spring
加密和解密属性值(对称或非对称)
结合Eureka实现服务发现
Build server
-
New Spring Boot project configserver
-
Introducing depends spring-cloud-config-server
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-config-server</artifactId> </dependency>
-
Introducing spring-boot-starter-web
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>
-
The main program to add comments @EnableConfigServer
@SpringBootApplication @EnableConfigServer public class ConfigserverApplication { public static void main(String[] args) { SpringApplication.run(ConfigserverApplication.class, args); } }
-
Setting properties
used herein .properties way configuration. You can replace .yml own way equally effective. Configuration information needs to be placed in bootstrap.properties.
1) Git stored configuration file example
# configuration files are stored in the case of Git spring.cloud.config.server.git.uri = http: // your ip: port your number / *** / * .git the Spring. Master-Paths = spring.cloud.config.server.git.search cloud.config.label = / spring.cloud.config.server.git.username = username
spring.cloud.config.server.git.password password =
2) local storage profile
case # configuration files are stored in the local # Note: folders have access spring.profiles.active = native spring.cloud.config.server.native.search-locations = local address
Client Configuration
pom.xml
Dependence on the introduction of config file pom.xml
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
bootstrap.properties
Bootstrap.properties create a file in the resources directory, as to why, if this rather than application.properties file is determined by the loading mechanism, the load time will be loaded bootstrap.properties file and then load application.properties, document reads as follows:
spring.application.name=自定义的名
spring.cloud.config.profile=eurekaserver
spring.cloud.config.label=master
spring.cloud.config.uri=http://localhost:9008/