Nacos集群开启了权限验证之后 nacos.core.auth.enabled=true,项目配置了Nacos集群启动报错 403 unknow user。相关配置如下:
pom.xml
<!--spring cloud Hoxton.SR1--> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>Hoxton.SR1</version> <type>pom</type> <scope>import</scope> </dependency> <!--spring cloud alibaba 2.1.0.RELEASE--> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-alibaba-dependencies</artifactId> <version>2.1.0.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency>
application.yml
spring:
cloud:
nacos:
discovery:
server-addr: 192.168.x.x:8848,192.168.x.x:8848,192.168.x.x:8848
username: nacos
password: nacos
namespace: public
说是要升级spring-cloud-alibaba-dependenceies的版本和nacos-client的版本。修改之后的配置如下
pom.xml
<!--spring cloud Hoxton.SR1--> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>Hoxton.SR1</version> <type>pom</type> <scope>import</scope> </dependency> <!--spring cloud alibaba 2.1.0.RELEASE--> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-alibaba-dependencies</artifactId> <version>2.2.0.RELEASE</version> <exclusions> <exclusion> <groupId>com.alibaba.nacos</groupId> <artifactId>nacos-client</artifactId> </exclusion> </exclusions> <type>pom</type> <scope>import</scope> </dependency> <dependency> <groupId>com.alibaba.nacos</groupId> <artifactId>nacos-client</artifactId> <version>1.2.1</version> </dependency>
升级之后启动项目。正常!!!
我以为就结束了,在集成了nacos config 配置中心之后,又幺蛾子了。又出现了 403 Forbidden unknown user!错误。
到源码里面看 nacos-cliend 1.2.1 中没有username 和 password 两个字段 然后把 cloud 的版本升级到2.2.2 nacos client 对应的版本是1.3.2
项目根目录的pom.xml
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>2.2.2.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>Hoxton.SR1</version> <type>pom</type> <scope>import</scope> </dependency> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-alibaba-dependencies</artifactId> <version>2.2.2.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency>
子模块的pom.xml
<dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId> </dependency>
启动正常!!!
参考:
https://cxybb.com/article/zhaojiyuan1024/117407544
https://blog.csdn.net/e274794140/article/details/119215433