微服务的一些问题:
(1)不方便维护;
(2)配置内容的安全与权限;
(3)更新配置项目需重启
统一配置中心:
远端git ——> config-server <——> 本地git
|
|
各个服务
config server开发:
(1)配置注释
@SpringBootApplication
@EnableDiscoveryClient
@EnableConfigServer
public class ConfigApplication {
(2)设置yml文件
eureka和git要设置
比如上传了order.yml配置文件,可以进行格式转换,这么获取:
http://localhost:8080/order-a.properties
http://localhost:8080/order-b.properties
http://localhost:8080/order-a.yml
http://localhost:8080/order-b.json
如果在yml中加了:
env:
dev
就可以这么访问:
http://localhost:8080/order-dev.json
对于test,则同理
如果再加一个属性:
label: release
那么久这么访问:
http://localhost:8080/release/order-dev.json
简单说这么调用的:
/{name}-{profiles}.yml
/{label}/{name}-{profiles}.yml
name:服务名
profile:环境
label:分支
config client开发:
spring:
application:
name: health-check
cloud:
config:
discovery:
service-id: CONFIG
enabled: true
profile: dev
然后properties.yml改成 bootstrap.yml。为什么要改名呢,因为如果从config服务中获取配置文件,就会存在两个properties.yml,spring cloud会混淆。
当然如果你在服务器上部署的eureka,是要加上这一段的(本机的8761端口则不用):
eureka:
client:
service-url:
defaultZone: ***
另外有一个要点:
当同时存在 order-dev.yml 和 order.yml,config的处理方式是将两个合并之后给出合并后的结果。因此,order.yml可以用作公共的配置文件