springboot Profile pulled --git unified configuration management center

springboot profiles detached, easy to read the corresponding server configuration file to avoid frequent changes to the project profile, debug and release affect the project

1. Create a unified configuration center project conifg

1) pom configuration dependent

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>Finchley.SR2</spring-cloud.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-monitor</artifactId>
</dependency>
</dependencies>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

2)yml文件配置
the Spring: 
the Application:
name: config
Cloud:
config:
Server:
git:
uri: https://gitee.com/XXXX/XXXXXX.git
username: XXXXXXX
password: XXXXXXXXX
Eureka:
Client:
Service-url:
defaultzone: HTTP: // localhost: 8000 / Eureka /
Management:
Endpoints:
Web:
EXPOSE: "*"

2. create a private project git config-repo is used to store configuration files

3. configure the project can see the corresponding configuration file content
http: // localhost: 8002 /XXXXX/user-dev.yml

4. configure client reads the configuration file
1) client configuration pom
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-client</artifactId>
</dependency>
2)客户端yml文件配置
spring:
application:
name: XXXXXX
cloud:
config:
discovery:
enabled: true
service-id: CONFIG
profile: dev



eureka:
client:
service-url:
defaultZone: http://localhost:8000/eureka/
instance:
prefer-ip-address: true
lease-renewal-interval-in-seconds: 1 # 单机时关闭eureka 保护模式
lease-expiration-duration-in-seconds: 2


Guess you like

Origin www.cnblogs.com/flyyu1/p/11445723.html