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]
这就是因为在程序启动的时候无法读取到配置信息,而又引入了注册和配合中心,所以会一直默认查找本地的信息。
推荐阅读
- 微服务|微服务系列:服务发现与注册-----Eureka(面试突击!你想了解的Eureka都在这里.持续更新中......)
- 每日一书|每日一书丨学习微服务最好的方式(阅读《微服务架构设计模式》)
- 架构设计|使用Axon Framework探索CQRS架构系列(一)(命令, 命令总线 和 命令处理组件)
- SpringBoot实体配置详解
- #|Spring Cloud 常用组件
- java|熔断的意义
- java|Spring Boot配置文件放在jar外部
- Spring|spring-cloud开发微服务笔记(二)(高可用Eureka注册中心的搭建与RestTemplate和Fengin客户端调用微服务示例)
- 为什么要使用微服务
- 微服务|Eureka的高可用以及服务提供者、服务消费者集群之间的调用方式