Currently, in order to use @ServiceConnection in beans along with
slice test annotations @ImportAutoConfiguration(ServiceConnectionAutoConfiguration.class)
should be added to make it work. This commit register
ServiceConnectionAutoConfiguration in specific slice test annotations.
See gh-35252
Comment From: wilkinsona
Thanks for the PR, @eddumelendez.
These changes introduce a cycle between spring-boot-testcontainers and spring-boot-test-autoconfigure:
- the former has
.importsfiles insrc/main/resourcesfor each of the sliced test annotations defined by the latter - the latter has tests that make use of
@ServiceConnectionwhich is defined by the former
I'm not sure how best to break this cycle. A couple of options:
- move all of the tests into
spring-boot-testcontainersand remove the test dependency onspring-boot-testcontainersfromspring-boot-test-autoconfigure - merge the
.importsfiles into those already inspring-boot-test-autoconfigurebut this would require support for an import being "optional" asspring-boot-testcontainerswouldn't necessarily be on the classpath when usingspring-boot-test-autoconfigure
1 feels the slightly better of these two options. There may also be others that I've overlooked. I'll discuss things with the team.
Comment From: wilkinsona
Thanks very much for the PR, @eddumelendez. In the end, we went with the second of the two options above. An entry in a .imports file can now be prefixed with optional:. An optional import that is not present on the classpath will be ignored.