相关推荐recommended
2.2.1版本nacos报错org.springframework.context.ApplicationContextException: Unable to start web server; n
作者:mmseoamin日期:2023-11-30

2.2.1版本nacos报错org.springframework.context.ApplicationContextException: Unable to start web server; n,6c76776e623644a897f4645d2d083647.png,第1张

 

报错信息:

org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat

Caused by: 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

我们转到错误中的网址:https://nacos.io/zh-cn/docs/v2/guide/user/auth.html

这是nacos官方文档关于配置属性的说明,对应下载的nacos文件位置为:nacos-->conf-->application.properties

重点是nacos.core.auth.plugin.nacos.token.secret.key字段

2.2.1版本nacos报错org.springframework.context.ApplicationContextException: Unable to start web server; n,82e08a8e6f8f400e87362964f789061c.png,第2张

 

再结合官方文档发现,在2.2.0.1版本之后,该字段默认为空,我们要手动赋值,不然就会无法启动

如果是自己的nacos,不关心安全,可以在配置文件中将该字段设置成:

SecretKey012345678901234567890123456789012345678901234567890123456789

2.2.1版本nacos报错org.springframework.context.ApplicationContextException: Unable to start web server; n,c24aed5be2c34814a8c5c19fb645c0d2.png,第3张

2.2.1版本nacos报错org.springframework.context.ApplicationContextException: Unable to start web server; n,1ec887d1480748c7ad75a7ee1e0806c9.png,第4张

 

在使用高版本nacos后,还有一个坑,nacos会默认使用集群方式启动,会启动失败,我们可以在nacos-->bin-->startup.cmd文件中将MODE属性改为  standalone  

 2.2.1版本nacos报错org.springframework.context.ApplicationContextException: Unable to start web server; n,093fd3b74c094325b0e0a8c5adb4fbe0.png,第5张