在上几篇的内容中,实现了多模块开发,服务间的调用、预警、网关等内容。
上几篇的网址:https://blog.csdn.net/xcc_2269861428/category_9481090.html
那么在我们正式上线时,肯定会是不同的配置文件的,这要如何修改呢?这里使用Spring Cloud Config
第一步:创建项目
选择:Spring Cloud Config中的Config Server 和Srping Cloud Discovery中的Eureka Discovery Client
第二步:在码云上创建一个项目(https://gitee.com/)
创建一个快手项目的配置文件
创建好项目后,我们开始配置conf-server项目的配置文件
第三步:配置conf-server
1),引入配置信息
#服务名称
spring:
application:
name: config-server
cloud:
config:
server:
git:
uri: https://gitee.com/xu_great_wall/spring_cloud_test.git
username: xxxx
password: xxxx
timeout: 5
default-label: master
#服务的端口号
server:
port: 9100
#指定注册中心地址
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8671/eureka/
2) 启动类上加注解@EnableConfigServer
启动项目访问kuaishou-download-pro.yml,看是否可以访问到(http://localhost:9100/kuaishou-download-pro.yml)
可以访问到,证明配置成功了。
第四步:开始修改我们实际要使用配置文件的项目
1)、要引入如下依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-client</artifactId>
</dependency>
2)将原来的application.yml 重命名为bootstrap.yml 这是硬性要求
3)、修改配置文件,引入要去哪里找配置文件
#指定注册中心地址
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8671/eureka/
#服务的名称
spring:
application:
name: kuaishou-download
#指定从哪个配置中心读取
cloud:
config:
discovery:
service-id: CONFIG-SERVER
enabled: true
profile: pro
label: master
启动项目,发现Fetching config from server at : http://EDZ-20180525PUZ:9100/ 已经开始访问了
查看端口,证明启动的是我们在git上配置的
把端口改成8084
重启项目再看看启动的端口号
创建一个dev在git上
修改我们项目的环境为dev
完美的走的8086