nacos 增加登陆权限验证后,客户端启动连接报403

搭建微服务项目,对应的版本如下

<!-- springboot的版本 -->
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-dependencies</artifactId>
	<version>2.2.2.RELEASE</version>
	<type>pom</type>
	<scope>import</scope>
</dependency>
<!-- springcloud的版本 -->
<dependency>
	<groupId>org.springframework.cloud</groupId>
	<artifactId>spring-cloud-dependencies</artifactId>
	<version>Hoxton.SR2</version>
	<type>pom</type>
	<scope>import</scope>
</dependency>
<!-- springcloudalibaba的版本 -->
<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>	

使用nacos作为注册中心,开启鉴权后,启动服务报错如下:

022-11-08 15:00:14 [INFO][com.alibaba.cloud.nacos.registry.NacosServiceRegistry][74]-> De-registering from Nacos Server now...
2022-11-08 15:00:14 [ERROR][com.alibaba.cloud.nacos.registry.NacosServiceRegistry][89]-> ERR_NACOS_DEREGISTER, de-register failed...NacosRegistration{nacosDiscoveryProperties=NacosDiscoveryProperties{serverAddr='localhost:8848', endpoint='', namespace='', watchDelay=30000, logName='', service='cloudalibaba-sentinel-service', weight=1.0, clusterName='DEFAULT', namingLoadCacheAtStart='false', metadata={preserved.register.source=SPRING_CLOUD}, registerEnabled=true, ip='192.168.199.1', networkInterface='', port=8401, secure=false, accessKey='', secretKey=''}},
java.lang.IllegalStateException: failed to req API:/nacos/v1/ns/instance after all servers([localhost:8848]) tried: failed to req API:localhost:8848/nacos/v1/ns/instance. code:403 msg: <html><body><h1>Whitelabel Error Page</h1><p>This application has no explicit mapping for /error, so you are seeing this as a fallback.</p><div id='created'>Tue Nov 08 15:00:14 CST 2022</div><div>There was an unexpected error (type=Forbidden, status=403).</div></body></html>
	at com.alibaba.nacos.client.naming.net.NamingProxy.reqAPI(NamingProxy.java:464)
	at com.alibaba.nacos.client.naming.net.NamingProxy.reqAPI(NamingProxy.java:386)
	at com.alibaba.nacos.client.naming.net.NamingProxy.deregisterService(NamingProxy.java:205)
	at com.alibaba.nacos.client.naming.NacosNamingService.deregisterInstance(NacosNamingService.java:244)
	at com.alibaba.nacos.client.naming.NacosNamingService.deregisterInstance(NacosNamingService.java:231)
	at com.alibaba.nacos.client.naming.NacosNamingService.deregisterInstance(NacosNamingService.java:221)
	at com.alibaba.cloud.nacos.registry.NacosServiceRegistry.deregister(NacosServiceRegistry.java:85)
	at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.deregister(AbstractAutoServiceRegistration.java:256)
	at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.stop(AbstractAutoServiceRegistration.java:271)
	at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.destroy(AbstractAutoServiceRegistration.java:208)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:389)
	at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeDestroyMethods(InitDestroyAnnotationBeanPostProcessor.java:347)
	at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeDestruction(InitDestroyAnnotationBeanPostProcessor.java:177)
	at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:242)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:571)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:543)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingleton(DefaultListableBeanFactory.java:1072)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:504)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingletons(DefaultListableBeanFactory.java:1065)
	at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1060)
	at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1029)
	at org.springframework.context.support.AbstractApplicationContext$1.run(AbstractApplicationContext.java:948)
2022-11-08 15:00:14 [INFO][com.alibaba.cloud.nacos.registry.NacosServiceRegistry][93]-> De-registration finished.

查看配置,已经添加了账号和密码,但就是一直报错,猜测是springcloud alibaba 版本的问题,将springcloud alibaba 的版本升级成2.2.2.RELEASE;如下配置,问题解决,启动成功。

<!-- springboot的版本 -->
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-dependencies</artifactId>
	<version>2.2.2.RELEASE</version>
	<type>pom</type>
	<scope>import</scope>
</dependency>
<!-- springcloud的版本 -->
<dependency>
	<groupId>org.springframework.cloud</groupId>
	<artifactId>spring-cloud-dependencies</artifactId>
	<version>Hoxton.SR2</version>
	<type>pom</type>
	<scope>import</scope>
</dependency>
<!-- springcloudalibaba的版本 -->
<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>	

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
如果你在启动 Nacos 后遇到了无法连接数据库的问题,可以参考以下步骤进行排查: 1. 检查数据库配置:确保你在 Nacos 的配置文件(如 `application.properties` 或 `application.yml`)中正确配置了数据库连接信息,包括数据库类型、主机名、端口号、用户名和密码等。确保这些配置与你的实际数据库配置一致。 2. 检查数据库服务是否正常运行:确认你的数据库服务(如 MySQL、Oracle 等)已经正确启动并且能够正常连接。你可以尝试使用数据库客户端工具连接数据库,并验证用户名和密码是否正确。 3. 检查数据库权限:确保你所使用的数据库账户具有足够的权限来创建、修改和访问 Nacos 所需的表和数据。 4. 检查数据库连接参数:检查数据库连接参数是否正确,包括 URL 格式、驱动程序等。不同的数据库类型可能有不同的连接参数格式,确保你使用了正确的参数。 5. 检查数据库防火墙设置:如果你的数据库服务器启用了防火墙,确保允许来自 Nacos 服务器的数据库连接请求通过防火墙。 6. 查看 Nacos 日志:检查 Nacos 的日志文件,查找相关的错误或异常信息。日志文件通常位于 Nacos 安装目录下的 `logs` 文件夹中。 如果以上步骤都没有解决问题,你可以提供更多的详细信息,例如数据库类型、Nacos 版本、具体的错误日志等,以便我们更好地帮助你解决问题。
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值