服务启动报错: [ main] c.a.n.c.config.http.ServerHttpAgent : no available server

场景:

一个服务,注册中心使用nacos

 

服务启动时报错:

2024-07-19 13:11:17.466 ERROR 32188 --- [ main] c.a.n.c.config.http.ServerHttpAgent : [NACOS SocketTimeoutException httpGet] currentServerAddr:http://localhost:8848, err : connect timed out
2024-07-19 13:11:18.467 ERROR 32188 --- [ main] c.a.n.c.config.http.ServerHttpAgent : [NACOS SocketTimeoutException httpGet] currentServerAddr:http://localhost:8848, err : connect timed out
2024-07-19 13:11:19.468 ERROR 32188 --- [ main] c.a.n.c.config.http.ServerHttpAgent : [NACOS SocketTimeoutException httpGet] currentServerAddr:http://localhost:8848, err : connect timed out
2024-07-19 13:11:19.468 ERROR 32188 --- [ main] c.a.n.c.config.http.ServerHttpAgent : no available server
2024-07-19 13:11:19.468 ERROR 32188 --- [ main] c.a.n.client.config.impl.ClientWorker : [fixed-localhost_8848] [sub-server] get server config exception, dataId=service-verificationcode, group=DEFAULT_GROUP, tenant=

java.net.ConnectException: no available server
at com.alibaba.nacos.client.config.http.ServerHttpAgent.httpGet(ServerHttpAgent.java:134) ~[nacos-client-1.4.1.jar:na]
at com.alibaba.nacos.client.config.http.MetricsHttpAgent.httpGet(MetricsHttpAgent.java:51) ~[nacos-client-1.4.1.jar:na]
at com.alibaba.nacos.client.config.impl.ClientWorker.getServerConfig(ClientWorker.java:274) ~[nacos-client-1.4.1.jar:na]
at com.alibaba.nacos.client.config.NacosConfigService.getConfigInner(NacosConfigService.java:155) [nacos-client-1.4.1.jar:na]
at com.alibaba.nacos.client.config.NacosConfigService.getConfig(NacosConfigService.java:98) [nacos-client-1.4.1.jar:na]
at com.alibaba.cloud.nacos.client.NacosPropertySourceBuilder.loadNacosData(NacosPropertySourceBuilder.java:85) [spring-cloud-starter-alibaba-nacos-config-2021.1.jar:2021.1]
at com.alibaba.cloud.nacos.client.NacosPropertySourceBuilder.build(NacosPropertySourceBuilder.java:73) [spring-cloud-starter-alibaba-nacos-config-2021.1.jar:2021.1]
at com.alibaba.cloud.nacos.client.NacosPropertySourceLocator.loadNacosPropertySource(NacosPropertySourceLocator.java:199) [spring-cloud-starter-alibaba-nacos-config-2021.1.jar:2021.1]
at com.alibaba.cloud.nacos.client.NacosPropertySourceLocator.loadNacosDataIfPresent(NacosPropertySourceLocator.java:186) [spring-cloud-starter-alibaba-nacos-config-2021.1.jar:2021.1]
at com.alibaba.cloud.nacos.client.NacosPropertySourceLocator.loadApplicationConfiguration(NacosPropertySourceLocator.java:141) [spring-cloud-starter-alibaba-nacos-config-2021.1.jar:2021.1]
at com.alibaba.cloud.nacos.client.NacosPropertySourceLocator.locate(NacosPropertySourceLocator.java:103) [spring-cloud-starter-alibaba-nacos-config-2021.1.jar:2021.1]
at org.springframework.cloud.bootstrap.config.PropertySourceLocator.locateCollection(PropertySourceLocator.java:51) [spring-cloud-context-3.0.1.jar:3.0.1]
at org.springframework.cloud.bootstrap.config.PropertySourceLocator.locateCollection(PropertySourceLocator.java:47) [spring-cloud-context-3.0.1.jar:3.0.1]
at org.springframework.cloud.bootstrap.config.PropertySourceBootstrapConfiguration.initialize(PropertySourceBootstrapConfiguration.java:95) [spring-cloud-context-3.0.1.jar:3.0.1]
at org.springframework.boot.SpringApplication.applyInitializers(SpringApplication.java:639) [spring-boot-2.4.13.jar:2.4.13]
at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:402) [spring-boot-2.4.13.jar:2.4.13]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:338) [spring-boot-2.4.13.jar:2.4.13]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1329) [spring-boot-2.4.13.jar:2.4.13]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1318) [spring-boot-2.4.13.jar:2.4.13]

 

application.yml 中配置的nacos地址是192.168.5.12 ,但是启动时却是调用的 localhost:8848

仔细看报错信息 spring-cloud-starter-alibaba-nacos-config 怎么调用了nacos配置中心,可是这个服务没有用bootstrap.yml的配置

发现是pom中引入了配置中心的依赖

        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-bootstrap</artifactId>
        </dependency>

 

删除pom.xml中的nacos配置中心的依赖,则报错消失

 

posted on 2024-07-19 16:04  欢跳的心  阅读(174)  评论(0编辑  收藏  举报