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值请酌情修改。

猜你喜欢

转载自blog.csdn.net/weixin_47061482/article/details/132718984