我想添加数据库连接的重试功能,直到该应用程序获取它为止。因为我在 dataSource
上使用了弹簧重返,但它不起作用。它引发了以下错误,
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'jdbcTemplate' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/JdbcTemplateConfiguration.class]: Unsatisfied dependency expressed through method 'jdbcTemplate' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: ExistingValue must be an instance of com.zaxxer.hikari.HikariDataSource
我看到了调试日志,但这些错误并没有帮助。这是示例源代码。请
注意:我的应用需要构建中提到的依赖项。我只提取了重试部分。
I would like to add the retry feature for database connection certain number of times until the app acquires it. For the I have used the spring-retry on the DataSource
but it is not working. It is throwing the following error
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'jdbcTemplate' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/JdbcTemplateConfiguration.class]: Unsatisfied dependency expressed through method 'jdbcTemplate' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: ExistingValue must be an instance of com.zaxxer.hikari.HikariDataSource
I have seen the debug logs but those are not helpful. Here is the sample source code . kindly help
Note: the dependencies mentioned in build.gradle is required for my app. I have only extracted the retry part.
发布评论
评论(1)
您的用例将延迟春季启动的开始,直到数据库启动为止。弹簧实际上是用一个可以做到这一点的组件的。 是该组件,自春季1.x以来就已经存在。
您可以将其添加为bean,它将等待进一步的引导程序,直到数据库启动为止。
有关更详细的说明,请参见我的博客文章 。
Your use-case is delaying the start of Spring Boot until your database is up. Spring actually ships with a component that does that. The
DatabaseStartupValidator
is that component and has existed since about Spring 1.x.You can add it as a bean and it will wait for further bootstrapping until the database is up.
For a more detailed explanation see this blog post of mine.