1.搭建Config Server
<1>pom.xml中引入依赖
<2>编写配置文件application.yml
<3>在src/main/resources创建配置文件
<4>在启动类上增加注解@EnableConfigServer
<5>启动工程,测试应用
2.搭建Config Client
<1>pom.xml中引入依赖
<2>编写配置文件bootstrap.yml
<3>在启动类上增加注解@RestController
<4>启动工程测试应用
详细:
1.搭建Config Server
<1>pom.xml中引入依赖
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
</dependencies>
<2>编写配置文件application.yml
spring:
application:
name:
config
profiles:
active: native #使用本地文件系统的存储方式来保存配置信息
cloud:
config:
server:
native:
search-locations: classpath:/shared
server:
port:
8888
<3>在src/main/resources/shared创建配置文件(新建shared目录)
application-order.yml
clientParam:
native-order-1.0
eureka:
instance:
prefe-ip-address:true #是否显示主机的IP
client:
registerWithEureka: true
fetchRegistry: false
serviceUrl:
defaultZone: http://localhost:8762/eureka/ #指定Eureka服务端地址
spring:
application:
name:
order #模块的名称
server:
port:
7000 #指定该Eureka实例的端口号
<4>在启动类上增加注解@EnableConfigServer
<5>启动工程,测试应用
http:localhost:8888/config/order
2.搭建Config Client
<1>pom.xml中引入依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<2>编写配置文件bootstrap.yml
spring:
application:
name:
order
cloud:
config:
profile:
order
uri:
http://localhost:8888/ #配置中心
server:
port:7000
<3>启动工程测试应用
成功!