Skip to content

When using checkpoint-restore and Hikari, dependency injection fails if the HikariDataSource has been replaced or wrapped #37580

@sdeleuze

Description

@sdeleuze

While working on https://github.com/sdeleuze/spring-petclinic-data-jdbc/tree/crac, I figured out that when org.crac:crac:1.4.0 dependency is in the classpath, ClinicServiceTests fails with the following error:

aused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'hikariCheckpointRestoreLifecycle' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Unsatisfied dependency expressed through method 'hikariCheckpointRestoreLifecycle' parameter 0: No qualifying bean of type 'com.zaxxer.hikari.HikariDataSource' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
	at app//org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:801)
	at app//org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:545)
	at app//org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1336)
	at app//org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1166)
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'hikariCheckpointRestoreLifecycle' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Unsatisfied dependency expressed through method 'hikariCheckpointRestoreLifecycle' parameter 0: No qualifying bean of type 'com.zaxxer.hikari.HikariDataSource' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
	at app//org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:801)
	at app//org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:545)
	at app//org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1336)

A workaround is to specify @AutoConfigureTestDatabase(replace = Replace.AUTO_CONFIGURED) but would be nice it works out of the box (I added it to the branch so make sure to remove it to reproduce).

As found by @wilkinsona, it also fails if the data source has been wrapped by a bean post-processor as the type changes.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions