1. Introduction
Spring Cloud Config provides server and client support for external configurations in distributed systems. With config Server, you can manage the external properties of your application in all environments. The conceptual mappings on the client and server are the same as spring Environment
and PropertySource
abstraction, so they fit well with spring applications, but can be used with any application that runs in any language. As your application passes through the deployment process from developer to test and production, you can manage the configuration between these environments and determine everything that your application needs to run when it is migrated. The default implementation of the server storage backend uses git, which makes it easy to support the configuration environment for the label version and access to the various tools for managing content. It is easy to add an alternative implementation and insert it using the spring configuration.
2. Introduce the POM-related jar package, where Pom.xml is configured as follows:
<?xml version= "1.0" encoding= "UTF-8"?> <project xmlns= "http://maven.apache.org/POM/4.0.0" xmlns:xsi= "http ://www.w3.org/2001/XMLSchema-instance "xsi:schemalocation=" http://maven.apache.org/POM/4.0.0/http Maven.apache.org/xsd/maven-4.0.0.xsd "> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.ml.honghu</groupId> <artifactId>commonservice</artifactId> <v Ersion>0.0.1-snapshot</version> </parent> <artifactid>commonservice-config</artifa ctid> <packaging>jar</packaging> <name>commonservice-config</name> <descrip Tion>config server</description> <dependencies> <dependency> <groupid >org.springframework.cloud</groupId> <artifactId>spring-cloud-config-server</artifactId> </dependency> <depenDency> <groupId>org.springframework.cloud</groupId> <artifactid>spring-clou d-starter-eureka</artifactid> </dependency> <dependency> <grou Pid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-security</ar Tifactid> </dependency> <dependency> <groupid>org.springframework. Boot</groupid> <artifactId>spring-boot-starter-test</artifactId> <scope> test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <a Rtifactid>spring-boot-maven-plugin</artifactid> <executions> <exec Ution> <id>1</id> <goals> <goal>repackag E</goal> </goals> </execution> <execution> <id>2</id> <goals> <goal>build-info</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project>
3. Configapplication.java boot file configuration in Src/main/java:
Package Com.ml.honghu; Import org.springframework.boot.SpringApplication; Import org.springframework.boot.autoconfigure.SpringBootApplication; Import Org.springframework.cloud.config.server.EnableConfigServer; Import org.springframework.cloud.netflix.eureka.EnableEurekaClient; @EnableConfigServer @EnableEurekaClient @SpringBootApplication public class Configapplication { public static void Main (string[] args) { springapplication.run (configapplication.class, args); } }
4. BOOTSTRAP.YML Configuration under Src/main/resource
server:port:8888 Spring:application:name:commonservice-config-server Profiles:active:discovery,native cloud:config:server:git:uri:http://192. 168.0.254/honghu.../honghu-config.git Username:honghu password:123456 searchpaths:conf Ig-dev security:basic:enabled:true User:name:honghu password:123456 eureka:client:s Erviceurl:defaultzone:http://honghu:[email protected]:8761/eureka/honghuzone:http://honghu:[email&n bsp;protected]:8761/eureka/registry-fetch-interval-seconds:300 Availability-zones:honghu:honghuzone Instance:prefer-ip-address:true metadatamap:version:1.0 variant:a User: ${security.u Ser.name} password: ${security.user.password} management:security:enabled:false
Note: If you do not load the profile information from a remote git or svn library, you can configure the load local address, such as the configuration using Windows:
Server: port:8888 Spring: application: name:commonservice-config-server Profiles: Active:discovery,native Cloud: config: server: <span style= "color: #ff0000;" >native.searchLocations:d:/honghu-config</span> Security: basic: enabled:true User: name:honghu password:123456 Eureka: client: serviceurl: defaultzone:http:/ /honghu:[email protected]:8761/eureka/ honghuzone:http://honghu:[email protected]:8761/eureka/ registry-fetch-interval-seconds:300 availability-zones: honghu:honghuzone instance: Prefer-ip-address:true metadatamap: version:1.0 variant:a User: ${security.user.name} Password: ${security.user.password} Management: Security: Enabled:false
To this, the entire Config service project configuration is complete!!
SOURCE Source
From now on, I will be documenting the process and essence of the recent development of the spring cloud micro-service cloud architecture to help more friends who are interested in developing the Spring cloud framework to explore the process of building the spring cloud architecture and how to use it in enterprise projects.
Spring Cloud Cloud Service architecture-commonservice-config Configuration service Setup