本地nacos启动失败,org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean **
Posted *宋清歌
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了本地nacos启动失败,org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean **相关的知识,希望对你有一定的参考价值。
总结:nacos-2.x.x要使用mysql5.7.x
项目使用若依3.1.0-cloud版本,因此要使用nacos-2.x.x的版本,下载并安装nacos后,
配置application.properties里的Config Module Related Configurations模块,
#*************** Config Module Related Configurations ***************#
### If use mysql as datasource:
spring.datasource.platform=mysql### Count of DB:
db.num=1### Connect URL of DB:
db.url.0=jdbc:mysql://127.0.0.1:3306/nacos_config?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC
db.user.0=SYC
db.password.0=123
然后再启动startup.cmd时会报错,需要使用单机模式,
编辑startup.cmd,设置里面的MODE为standalone
set MODE="standalone"
set FUNCTION_MODE="all"
set SERVER=nacos-server
set MODE_INDEX=-1
set FUNCTION_MODE_INDEX=-1
set SERVER_INDEX=-1
set EMBEDDED_STORAGE_INDEX=-1
set EMBEDDED_STORAGE=""
再次启动时报错
2022-09-09 16:30:29,073 ERROR Startup errors :
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'memoryMonitor' defined in URL [jar:file:/D:/Software/nacos/target/nacos-server.jar!/BOOT-INF/lib/nacos-config-2.1.1.jar!/com/alibaba/nacos/config/server/monitor/MemoryMonitor.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'asyncNotifyService': Unsatisfied dependency expressed through field 'dumpService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'externalDumpService': Invocation of init method failed; nested exception is ErrCode:500, ErrMsg:Nacos Server did not start because dumpservice bean construction failure :
No DataSource set
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:800)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:229)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1372)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1222)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.create
看着No DataSource set猜测可能是链接数据库问题,使用的mysql为5.6.x
升级为5.7.x
再次启动成功
"nacos is starting with standalone"
,--.
,--.'|
,--,: : | Nacos 2.1.1
,`--.'`| ' : ,---. Running in stand alone mode, All function modules
| : : | | ' ,'\\ .--.--. Port: 8848
: | \\ | : ,--.--. ,---. / / | / / ' Pid: 22716
| : ' '; | / \\ / \\. ; ,. :| : /`./ Console: http://192.168.56.1:8848/nacos/index.html
' ' ;. ;.--. .-. | / / '' | |: :| : ;_
| | | \\ | \\__\\/: . .. ' / ' | .; : \\ \\ `. https://nacos.io
' : | ; .' ," .--.; |' ; :__| : | `----. \\
| | '`--' / / ,. |' | '.'|\\ \\ / / /`--' /
' : | ; : .' \\ : : `----' '--'. /
; |.' | , .-./\\ \\ / `--'---'
'---' `--`---' `----'2022-09-09 16:43:26,404 INFO Tomcat initialized with port(s): 8848 (http)
2022-09-09 16:43:26,501 INFO Root WebApplicationContext: initialization completed in 2700 ms
2022-09-09 16:43:29,845 INFO Adding welcome page: class path resource [static/index.html]
2022-09-09 16:43:30,149 WARN You are asking Spring Security to ignore Ant [pattern='/**']. This is not recommended -- please use permitAll via HttpSecurity#authorizeHttpRequests instead.
2022-09-09 16:43:30,150 INFO Will not secure Ant [pattern='/**']
2022-09-09 16:43:30,175 INFO Will secure any request with [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@62e70ea3, org.springframework.security.web.context.SecurityContextPersistenceFilter@186978a6, org.springframework.security.web.header.HeaderWriterFilter@34a75079, org.springframework.security.web.csrf.CsrfFilter@72a85671, org.springframework.security.web.authentication.logout.LogoutFilter@7a7471ce, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@482d776b, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@132ddbab, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@3efe7086, org.springframework.security.web.session.SessionManagementFilter@107ed6fc, org.springframework.security.web.access.ExceptionTranslationFilter@631e06ab]
2022-09-09 16:43:30,195 INFO Exposing 1 endpoint(s) beneath base path '/actuator'
2022-09-09 16:43:30,238 INFO Tomcat started on port(s): 8848 (http) with context path '/nacos'
2022-09-09 16:43:30,259 INFO Nacos started successfully in stand alone mode. use external storage
Nacos 启动失败
由于最近学习 SpringCloudAlibaba ,故将学习过程中出现的问题加以总结。
Nacos 学习时遇到的问题
下载最新的 Nacos 版本在 Windows 直接运行脚本启动,首先报错第一个问题如下:
java.lang.IllegalArgumentException: db.num is null java.lang.RuntimeException: [db-load-error]load jdbc.properties error
解决步骤:
将 Nacos 下的 conf/application.properties 文件修改如下图所示
新建本地数据库 Nacos,执行 conf/nacos-mysql.sql 文件,确保本地数据库有此信息。
继续运行 startup.cmd 文件,继续出现主要报错如下所示:
Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
Unable to start embedded Tomcat
Error creating bean with name 'distroFilterRegistration' defined in class path resource
Error creating bean with name 'distroFilter'
java.net.UnknownHostException: jmenv.tbsite.net
解决步骤:
打开启动脚本文件 startup.cmd,修改如图所示即可
再次启动即可完成 nacos 的初始化启动。
以上是关于本地nacos启动失败,org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean **的主要内容,如果未能解决你的问题,请参考以下文章
Spring-Cloud-Alibaba Nacos 启动失败,窗口一闪而过