1、错误描述
启动的错误信息
2023-10-17 15:55:30.513 INFO --- [ main] o.s.b.w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 6128 ms
2023-10-17 15:55:31.468 WARN --- [ main] o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dataSourceScriptDatabaseInitializer' defined in class path resource [org/springframework/boot/autoconfigure/sql/init/DataSourceInitializationConfiguration.class]: Unsatisfied dependency expressed through method 'dataSourceScriptDatabaseInitializer' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dataSourceConfig': Unsatisfied dependency expressed through field 'defaultDruidProperties'; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'dataSourceConfig': Requested bean is currently in creation: Is there an unresolvable circular reference?
2023-10-17 15:55:31.535 INFO --- [ main] org.apache.catalina.core.StandardService : Stopping service [Tomcat]
2023-10-17 15:55:31.576 INFO --- [ main] o.s.b.a.l.ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2023-10-17 15:55:31.624 ERROR --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
The dependencies of some of the beans in the application context form a cycle:
dataSourceScriptDatabaseInitializer defined in class path resource [org/springframework/boot/autoconfigure/sql/init/DataSourceInitializationConfiguration.class]
┌─────┐
| dataSourceConfig (field private mysite.cloud.config.properties.DruidProperties mysite.cloud.config.DataSourceConfig.defaultDruidProperties)
└─────┘
Action:
Relying upon circular references is discouraged and they are prohibited by default. Update your application to remove the dependency cycle between beans. As a last resort, it may be possible to break the cycle automatically by setting spring.main.allow-circular-references to true.
与目标 VM 断开连接, 地址为: ''127.0.0.1:58995',传输: '套接字''
进程已结束,退出代码1
2、错误原因
我的包的引用的问题
列一下我的目录结构
common
|--common-core
|--common-datasource
|--common-auth
web
|--site
1、我把连接数据库的config类放到了common-datasource包中
2、我的common-auth中依赖了common-datasource包
错误的操作来了,我的site包同时依赖了common-datasource和common-auth包
就直接导致了同时引入了两个同样的config类
所以启动的时候就会报这个错误
3、解决办法
找到上述的问题点之后,引入auth的时候排除common-datasource包,或者是site去掉common-datasource的依赖都可以