当使用nacos作为注册中心时,很顺利,进如下配置(仅仅配置了ip和端口)
启动类加@EnableDiscoveryClient注解
nacos作为配置中心
当继续将nacos作为配置中心时
添加加依赖
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
改配置
控制台添加了与项目同名的配置
启动项目后报错
如下:
ERROR 16160 --- [ main] c.a.n.c.config.http.ServerHttpAgent : [NACOS SocketTimeoutException httpGet] currentServerAddr:http://localhost:8848
看样子是连不上nacos,而且连的是localhost:8848,我明明配置的是ip:8848,为何没用?
查阅官网资料后发现配置的不对,nacos需要在bootstrap.yml或bootstrap.properties进行配置,没在这配置默认配的http://localhost:8848
spring:
nacos-host: 47.99.123.209
nacos-port: 8848
main:
allow-bean-definition-overriding: true
application:
name: mall-member
cloud:
nacos:
discovery:
server-addr: ip:8848
userName: "nacos"
password: "nacos"
config:
server-addr: ip:8848
userName: "nacos"
password: "nacos"
file-extension: properties