本地配置方式:
1.配置中心启动类必须要有@EnableConfigServer注解
2.本地配置方式包括本地类路径和文件系统两种方式
首先设置spring.profiles.active为native,
然后spring.cloud.config.server.native.searchLocations 指向目标文件夹
这样Config Server启动时,
才能加载到对应的配置文件。
2.1文件系统方式
需要注意的是,当本地配置有多个文件夹时,file需要指定多个目录,
例:当configFile是根目录时,本地若同git方式一样指向该目录,会有问题,
用http地址访问时,需要加上子级目录+yml文件 例: http://localhost:9999/config/answer-service/answer-service-dev.yml
所以若要跟git方式一样,则采用多个文件配置方式。以英文 , 逗号隔开
search-locations: file:H:\lianyou\project\honda-shop\configFile\,file:H:\lianyou\project\honda-shop\configFile\eureka\
server: port: 9090 servlet: context-path: /config spring: application: name: config-server profiles: active: native cloud: config: server: native: search-locations: file:H:\lianyou\project\honda-shop\configFile\,file:H:\lianyou\project\honda-shop\configFile\eureka\,file:H:\lianyou\project\honda-shop\configFile\gateway\,file:H:\lianyou\project\honda-shop\configFile\wechat-service\,file:H:\lianyou\project\honda-shop\configFile\datebase\,file:H:\lianyou\project\honda-shop\configFile\redis\,file:H:\lianyou\project\honda-shop\configFile\system\
2.2类路径方式
通过在search-locations中指定classpath下的路径:
类路径也可同文件方式配置
spring: application: name: config-server profiles: active: native cloud: config: server: native: search-locations: classpath:/config
3.启动好后,其他微服务uri指向配置中心
spring: cloud: config: label: develop uri: http://shop-config.default.svc.cluster.local:9090/config name: wechat-service,eureka-client,redis,datebase-shop,common,feign profile: test
name:为yml文件名前部分,
profile:dev test pro 等等,为yml文件后部分
例:answer-service-dev.yml
配置好后先启动配置中心config-service,再启动其他微服务wechat-service即可查看,
也可只需启动配置中心,http访问对应路径也可查看