Nacos启动报错:Unsatisfied dependency expressed through field ‘jwtTokenManager‘

1、Nacos启动报错:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'basicAuthenticationFilter' defined in class path resource [com/alibaba/nacos/prometheus/filter/PrometheusAuthFilter.class]: Unsatisfied dependency expressed through method 'basicAuthenticationFilter' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'nacosAuthConfig' defined in URL [jar:file:/Users/moon/Downloads/nacos-2.2.1/distribution/target/nacos-server-2.2.1/nacos/target/nacos-server.jar!/BOOT-INF/lib/nacos-plugin-default-impl-2.2.1.jar!/com/alibaba/nacos/plugin/auth/impl/NacosAuthConfig.class]: Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'tokenManagerDelegate': Unsatisfied dependency expressed through field 'jwtTokenManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jwtTokenManager' defined in URL [jar:file:/Users/moon/Downloads/nacos-2.2.1/distribution/target/nacos-server-2.2.1/nacos/target/nacos-server.jar!/BOOT-INF/lib/nacos-plugin-default-impl-2.2.1.jar!/com/alibaba/nacos/plugin/auth/impl/token/impl/JwtTokenManager.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.alibaba.nacos.plugin.auth.impl.token.impl.JwtTokenManager]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: the length of secret key must great than or equal 32 bytes; And the secret key  must be encoded by base64.Please see https://nacos.io/zh-cn/docs/v2/guide/user/auth.html

在这里插入图片描述

重点看最后一句:原始密钥长度不得低于32字符,并且应该设置为Base64编码的字符串。请参看:https://nacos.io/zh-cn/blog/announcement-token-secret-key.html,看进去原来是自定义秘钥惹的祸。

在这里插入图片描述

更多细节内容参看官方文档关于Nacos默认token.secret.key及server.identity风险说明及解决方案公告

2、解决方案:

本机为例找到/Users/moon/Downloads/nacos-2.2.1/distribution/target/nacos-server-2.2.1/nacos/conf/application.properties ,在文件中填充密钥,然后重启nacos。

nacos.core.auth.plugin.nacos.token.secret.key=VGhpc0lzTXlDdXN0b21TZWNyZXRLZXkwMTIzNDU2Nzg=

在这里插入图片描述


视情况是否需要让客户端尽快过期掉旧token,当然如果是测试环境或者本地其实也大可不必改来改去【下边内容可忽略 】

在修改token.secret.key前,先修改token.expire.seconds为5,客户端默认每5s检查一次token是否过期,需要让客户端尽快过期掉旧token。

# 2.1.0版本前
nacos.core.auth.default.token.expire.seconds=5

# 2.1.0版本及更高版本
nacos.core.auth.plugin.nacos.token.expire.seconds=5

修改token.expire.seconds后重启集群,运行一段时间(超过原token.expire.seconds值,以保证所有客户端已经获取到新TTL)

注意:修改后会导致客户端较为频繁地调用login接口,修改前请确保Nacos Server集群的资源足够。

最后将token.secret.key修改为新值,并重启集群,token.expire.seconds值请酌情修改。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一只IT攻城狮

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值