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 加载
【spring cloud中使用nacos, application.yml和bootstrap.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]

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

    推荐阅读