引入spring-cloud-starter-bootstrap但不建bootstrap文件,导致nacos config 报错.longPolling.fixed-localhost_8848 ption httpPost] currentServerAddr: http://localhost:8848, err : Connection refused Connection refused

使用SpringCloud添加了一个新服务,上线报错:

[ERROR] 2023-02-16 12:40:29 785 [com.alibaba.nacos.client.config.http.ServerHttpAgent] [com.alibaba.nacos.client.Worker.longPolling.fixed-localhost_8848] (ServerHttpAgent.java:166) -> [NACOS ConnectException httpPost] currentServerAddr: http://localhost:8848, err : Connection refused (Connection refused)
[ERROR] 2023-02-16 12:40:29 787 [com.alibaba.nacos.client.config.http.ServerHttpAgent] [com.alibaba.nacos.client.Worker.longPolling.fixed-localhost_8848] (ServerHttpAgent.java:166) -> [NACOS ConnectException httpPost] currentServerAddr: http://localhost:8848, err : Connection refused (Connection refused)
[ERROR] 2023-02-16 12:40:29 788 [com.alibaba.nacos.client.config.http.ServerHttpAgent] [com.alibaba.nacos.client.Worker.longPolling.fixed-localhost_8848] (ServerHttpAgent.java:166) -> [NACOS ConnectException httpPost] currentServerAddr: http://localhost:8848, err : Connection refused (Connection refused)
[ERROR] 2023-02-16 12:40:29 790 [com.alibaba.nacos.client.config.http.ServerHttpAgent] [com.alibaba.nacos.client.Worker.longPolling.fixed-localhost_8848] (ServerHttpAgent.java:166) -> [NACOS ConnectException httpPost] currentServerAddr: http://localhost:8848, err : Connection refused (Connection refused)
[ERROR] 2023-02-16 12:40:29 790 [com.alibaba.nacos.client.config.impl.ClientWorker] [com.alibaba.nacos.client.Worker.longPolling.fixed-localhost_8848] (ClientWorker.java:454) -> [fixed-localhost_8848] [check-update] get changed dataId exception
java.net.ConnectException: [NACOS HTTP-POST] The maximum number of tolerable server reconnection errors has been reached
        at com.alibaba.nacos.client.config.http.ServerHttpAgent.httpPost(ServerHttpAgent.java:181)
        at com.alibaba.nacos.client.config.http.MetricsHttpAgent.httpPost(MetricsHttpAgent.java:68)
        at com.alibaba.nacos.client.config.impl.ClientWorker.checkUpdateConfigStr(ClientWorker.java:441)
        at com.alibaba.nacos.client.config.impl.ClientWorker.checkUpdateDataIds(ClientWorker.java:408)
        at com.alibaba.nacos.client.config.impl.ClientWorker$LongPollingRunnable.run(ClientWorker.java:596)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
[ERROR] 2023-02-16 12:40:29 792 [com.alibaba.nacos.client.config.impl.ClientWorker] [com.alibaba.nacos.client.Worker.longPolling.fixed-localhost_8848] (ClientWorker.java:640) -> longPolling error :
java.net.ConnectException: [NACOS HTTP-POST] The maximum number of tolerable server reconnection errors has been reached
        at com.alibaba.nacos.client.config.http.ServerHttpAgent.httpPost(ServerHttpAgent.java:181)
        at com.alibaba.nacos.client.config.http.MetricsHttpAgent.httpPost(MetricsHttpAgent.java:68)
        at com.alibaba.nacos.client.config.impl.ClientWorker.checkUpdateConfigStr(ClientWorker.java:441)
        at com.alibaba.nacos.client.config.impl.ClientWorker.checkUpdateDataIds(ClientWorker.java:408)
        at com.alibaba.nacos.client.config.impl.ClientWorker$LongPollingRunnable.run(ClientWorker.java:596)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)

 看报错说的时nacos config client 使用了currentServerAddr: http://localhost:8848去连nacos 连不上报错

怎么会用这个地址连呢?

网上搜罗不到有用的解决方案

研究pom文件时发现

        <!--SpringCloud2020及以后的版本默认不启用 bootstrap 配置,我们需要在pom里面显式地引入:-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-bootstrap</artifactId>
        </dependency>

 之前的项目引用了这个依赖,

新项目里没有配置bootstrap.yml文件,导致线上读取不到nacos配置

添加配置文件bootstrap.yml后解决

 

 

spring:
  cloud:
    nacos:
      discovery:
        server-addr: 1xxxx.1:8848 #Nacos服务注册中心地址
      config:
        server-addr: 1xxxx.1:8848 #Nacos作为配置中心地址
        file-extension: yaml #指定yaml格式的配置

 

posted @ 2023-02-16 21:36  timseng  阅读(1140)  评论(0编辑  收藏  举报