使用springCloud的时候,配置信息一般是要从configServer加载的,为了取到配置信息,需要更早的取到配置,引导配置,因此把 config server 信息放在 bootstrap.yml,用来加载真正需要的配置信息。
org.springframework.cloud spring-cloud-dependencies 2021.0.1 pom import com.alibaba.cloud spring-cloud-starter-alibaba-nacos-config 2.2.5.RELEASEcom.alibaba.cloudspring-cloud-starter-alibaba-nacos-discovery2.2.5.RELEASE
spring:profiles:active: @profileActive@
代码如下:
server:port: 8082tomcat:accesslog:encoding: UTF-8spring:mvc:pathmatch:matching-strategy: ant_path_matcherapplication:name: pb-gatewaycloud:nacos:discovery:enabled: trueserver-addr: 192.168.85.128:8848namespace: c30d277b-745f-4f4a-adda-22a0d1a8efeegroup: devconfig:server-addr: 192.168.85.128:8848file-extension: yamlnamespace: c30d277b-745f-4f4a-adda-22a0d1a8efeegroup: devrefresh-enabled: true
将application-dev.yml中config配置移动到bootstrap.properties文件中
如下:
org.springframework.cloudspring-cloud-starter-bootstrap3.1.3
server:port: 8082tomcat:accesslog:encoding: UTF-8spring:mvc:pathmatch:matching-strategy: ant_path_matchercloud:nacos:discovery:enabled: trueserver-addr: 192.168.85.128:8848namespace: c30d277b-745f-4f4a-adda-22a0d1a8efeegroup: dev
spring.application.name=pb-gatewayspring.cloud.nacos.config.server-addr=192.168.85.128:8848spring.cloud.nacos.config.file-extension=yamlspring.cloud.nacos.config.namespace=c30d277b-745f-4f4a-adda-22a0d1a8efeespring.cloud.nacos.config.group=devspring.cloud.nacos.config.refresh-enabled=true
space=c30d277b-745f-4f4a-adda-22a0d1a8efee
spring.cloud.nacos.config.group=dev
spring.cloud.nacos.config.refresh-enabled=true
“