I'm in the process of migrating to Spring Boot 3. In Spring Boot 2 Resilience4J Retry was auto-configured and worked out of the box using the following setup:
application.yaml:
resilience4j.retry:
instances:
some-instance
# retry config here
Test class:
@SpringBootTest
public class TestClass {
@Autowired
private RetryRegistry retryRegistry;
@Test
void someTest() {
// perform test and evaluate retries using retryRegistry
}
}
However while updating to Spring Boot 3 using the following versions:
org.springframework.boot:spring-boot-starter:jar:3.0.0:compile
io.github.resilience4j:resilience4j-spring-boot2:jar:1.7.0:compile (derived from a Spring BoM)
The test in which the RetryRegistry was autowired failed with the following message:
Unsatisfied dependency expressed through field 'retryRegistry':
No qualifying bean of type 'io.github.resilience4j.retry.RetryRegistry' available:
expected at least 1 bean which qualifies as autowire candidate.
Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
I managed to fix the test by explicitly importing the Resilience4j Retry configuration in the test using:
@Import(io.github.resilience4j.retry.autoconfigure.RetryAutoConfiguration.class)
However, I'm wondering why the component scanning mechanism in Spring Boot 3 did not pick up the retry config in the first place. Would anyone know why Spring Boot 3 did not pick up the class during component scanning?
It seems that it is related to a new META-INF file being used instead of the old
spring.factories
file. From the documentation :The Resilience4J dependency used in the
spring-cloud-dependencies-parent
BoM still uses aspring.factories
file instead of the new file namedorg.springframework.boot.autoconfigure.AutoConfiguration.imports
. The new file has recently been introduced in Resilience4J (source).Overriding the version from the Spring BoM with version
2.0.2
for all the resilience dependencies fixed it for me. I will check in a few days whether the new Resilience4J version has been updated in the Spring BoM (or resilience4j-spring-boot3 has been introduced).[edit] As others have noticed,
resilience4j-spring-boot3
is already available. I'll start using it.