问题描述
SpringCloud的Nacos整合gateway网关后,已经配置了非本地的局域网里的nacos服务器,不过启动gateway后报错:
com.alibaba.nacos.shaded.io.grpc.netty.shaded.io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: localhost/0:0:0:0:0:0:0:1:9848
提示连接不上本地的127.0.0.1的nacos(9848是nacos的gRPC端口,是8848往上+1000的结果),所以看上去没有使用nacos自定义的IP和端口
不过我明确已经在application.yml中已经配置好了nacos,而且nacos中也能看到gateway服务已经连上了。
问题解决
经过排查,配置文件弄错了,gateway的配置文件需要写到bootstrap.yml中,之前放在application.yml中,它gateway还是去找bootstrap.yml,找不到,导致使用了默认的本机localhost的8848端口。
使用boostrap.yml
spring:
application:
name: test-gateway
cloud:
nacos:
discovery:
server-addr: 1.2.3.4:8848
username: nacos
password: nacos
gateway:
discovery:
locator:
enabled: true
routes:
- id: service_complaint_router
uri: lb://service-complaint
predicates:
- Path=/complaint/**
问题解决
文章评论