nacos2.2.1启动报错

发布时间 2023-03-22 21:13:45作者: RainbowMagic

启动nacos报以下错误

Caused by: 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:/D:/download/nacos-server-2.2.1.tar/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:/D:/download/nacos-server-2.2.1.tar/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

错误原因

打开nacos官方文档:https://nacos.io/zh-cn/docs/v2/guide/user/auth.html
可以看到,有些默认配置项在最新版本已经没有默认值,如果不配置则会无法启动nacos
img
需要在nacos/conf/application.properties文件中找到nacos.core.auth.plugin.nacos.token.secret.key配置项,在配置项中填入一个不低于32位的字符串即可,可以使用随机生成字符串的网站自动生成填入即可。
img
img

之后在nacos/bin目录执行startup.cmd -m standalone则会正常执行,不会发生错误。
img