2.5.0-M2 中对数据源初始化的更改已修复此问题。该示例在 2.5.0-M1 上失败:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.5.0-M1)
2021-03-09 15:00:37.772 INFO 84880 --- [ main] com.example.demo.DemoApplication : Starting DemoApplication using Java 1.8.0_252 on wilkinsona-a01.vmware.com with PID 84880 (/Users/awilkinson/dev/temp/datasource-issue-reproducer/target/classes started by awilkinson in /Users/awilkinson/dev/temp/datasource-issue-reproducer)
2021-03-09 15:00:37.773 INFO 84880 --- [ main] com.example.demo.DemoApplication : No active profile set, falling back to default profiles: default
2021-03-09 15:00:38.138 WARN 84880 --- [ main] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dataSource' defined in com.example.demo.DemoApplication: Unsatisfied dependency expressed through method 'dataSource' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'firstDataSource' defined in com.example.demo.DemoApplication: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerInvoker': Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'dataSource': Requested bean is currently in creation: Is there an unresolvable circular reference?
2021-03-09 15:00:38.144 INFO 84880 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-03-09 15:00:38.150 ERROR 84880 --- [ 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:
┌─────┐
| dataSource defined in com.example.demo.DemoApplication
↑ ↓
| firstDataSource defined in com.example.demo.DemoApplication
↑ ↓
| org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerInvoker
└─────┘
由于以下更改,它可以在 2.5.0-M2 上成功启动:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.5.0-M2)
2021-03-09 14:59:21.583 INFO 84719 --- [ main] com.example.demo.DemoApplication : Starting DemoApplication using Java 1.8.0_252 on wilkinsona-a01.vmware.com with PID 84719 (/Users/awilkinson/dev/temp/datasource-issue-reproducer/target/classes started by awilkinson in /Users/awilkinson/dev/temp/datasource-issue-reproducer)
2021-03-09 14:59:21.584 INFO 84719 --- [ main] com.example.demo.DemoApplication : No active profile set, falling back to default profiles: default
2021-03-09 14:59:21.986 INFO 84719 --- [ main] com.example.demo.DemoApplication : Started DemoApplication in 0.587 seconds (JVM running for 0.824)