spring cloud中使用nacos, application.yml和bootstrap.yml的区别

如果对大家有用,请点赞收藏支持,如果无用请多多包含!!!!

非常感谢!!!

 springboot项目启动报错:
     [NACOS SocketTimeoutException httpGet] currentServerAddr:http://localhost:8848, err : connect timed out

一、bootstrap.yml(bootstrap.properties)与application.yml(application.properties)执行顺序

        bootstrap.yml(bootstrap.properties)用来在程序引导时执行,应用于更加早期配置信息读取,如可以使用来配置application.yml中使用到参数等

       application.yml(application.properties) 应用程序特有配置信息,可以用来配置后续各个模块中需使用的公共参数等。

bootstrap.yml 先于 application.yml 加载

二、Nacos配置中使用application.yml会出现什么问题呢

[NACOS SocketTimeoutException httpGet] currentServerAddr:http://localhost:8848, err : connect timed out
[2m2020-05-30 14:36:17.679[0;39m [31mERROR[0;39m [35m7008[0;39m [2m---[0;39m [2m[           main][0;39m [36mc.a.n.c.config.http.ServerHttpAgent     [0;39m [2m:[0;39m [NACOS SocketTimeoutException httpGet] currentServerAddr:http://localhost:8848, err : connect timed out
[2m2020-05-30 14:36:17.680[0;39m [31mERROR[0;39m [35m7008[0;39m [2m---[0;39m [2m[           main][0;39m [36mc.a.n.c.config.http.ServerHttpAgent     [0;39m [2m:[0;39m no available server
[2m2020-05-30 14:36:17.709[0;39m [31mERROR[0;39m [35m7008[0;39m [2m---[0;39m [2m[           main][0;39m [36mc.a.n.client.config.impl.ClientWorker   [0;39m [2m:[0;39m [fixed-localhost_8848] [sub-server] get server config exception, dataId=mycloud-gateway, group=DEFAULT_GROUP, tenant=

java.net.ConnectException: no available server
	at com.alibaba.nacos.client.config.http.ServerHttpAgent.httpGet(ServerHttpAgent.java:123) ~[nacos-client-1.2.1.jar:na]
	at com.alibaba.nacos.client.config.http.MetricsHttpAgent.httpGet(MetricsHttpAgent.java:48) ~[nacos-client-1.2.1.jar:na]
	at com.alibaba.nacos.client.config.impl.ClientWorker.getServerConfig(ClientWorker.java:230) ~[nacos-client-1.2.1.jar:na]
	at com.alibaba.nacos.client.config.NacosConfigService.getConfigInner(NacosConfigService.java:143) [nacos-client-1.2.1.jar:na]
	at com.alibaba.nacos.client.config.NacosConfigService.getConfig(NacosConfigService.java:92) [nacos-client-1.2.1.jar:na]
	at com.alibaba.cloud.nacos.client.NacosPropertySourceBuilder.loadNacosData(NacosPropertySourceBuilder.java:85) [spring-cloud-starter-alibaba-nacos-config-2.2.1.RELEASE.jar:2.2.1.RELEASE]
	at com.alibaba.cloud.nacos.client.NacosPropertySourceBuilder.build(NacosPropertySourceBuilder.java:74) [spring-cloud-starter-alibaba-nacos-config-2.2.1.RELEASE.jar:2.2.1.RELEASE]
	at com.alibaba.cloud.nacos.client.NacosPropertySourceLocator.loadNacosPropertySource(NacosPropertySourceLocator.java:204) [spring-cloud-starter-alibaba-nacos-config-2.2.1.RELEASE.jar:2.2.1.RELEASE]
	at com.alibaba.cloud.nacos.client.NacosPropertySourceLocator.loadNacosDataIfPresent(NacosPropertySourceLocator.java:191) [spring-cloud-starter-alibaba-nacos-config-2.2.1.RELEASE.jar:2.2.1.RELEASE]
	at com.alibaba.cloud.nacos.client.NacosPropertySourceLocator.loadApplicationConfiguration(NacosPropertySourceLocator.java:142) [spring-cloud-starter-alibaba-nacos-config-2.2.1.RELEASE.jar:2.2.1.RELEASE]
	at com.alibaba.cloud.nacos.client.NacosPropertySourceLocator.locate(NacosPropertySourceLocator.java:103) [spring-cloud-starter-alibaba-nacos-config-2.2.1.RELEASE.jar:2.2.1.RELEASE]
	at org.springframework.cloud.bootstrap.config.PropertySourceLocator.locateCollection(PropertySourceLocator.java:52) [spring-cloud-context-2.2.2.RELEASE.jar:2.2.2.RELEASE]
	at org.springframework.cloud.bootstrap.config.PropertySourceLocator.locateCollection(PropertySourceLocator.java:47) [spring-cloud-context-2.2.2.RELEASE.jar:2.2.2.RELEASE]
	at org.springframework.cloud.bootstrap.config.PropertySourceBootstrapConfiguration.initialize(PropertySourceBootstrapConfiguration.java:97) [spring-cloud-context-2.2.2.RELEASE.jar:2.2.2.RELEASE]
	at org.springframework.boot.SpringApplication.applyInitializers(SpringApplication.java:626) [spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE]
	at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:370) [spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:314) [spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) [spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE]
	at com.itdu.GateWayApp.main(GateWayApp.java:18) [classes/:na]

这就是因为在程序启动的时候无法读取到配置信息,而又引入了注册和配合中心,所以会一直默认查找本地的信息。 

 

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值