-
Notifications
You must be signed in to change notification settings - Fork 40.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Spring Boot 3.4-M3: application container does not start when TestContainer beans depend on each other #42607
Comments
Thanks for the sample. I can reproduce the problem with 3.4.0-M3 but not with 3.4.0-SNAPSHOT. I suspect that's due to some of the changes that were made in #41996 where the container lifecycle management was simplified. For reference, here's the log with 3.4.0-SNAPSHOT when the test starts the app successfully:
Please given 3.4.0-SNAPSHOT (available from https://repo.spring.io/snapshot) a try and let us know if it works in your actual application as well as the sample. |
Hi @wilkinsona , thanks for getting back so quickly! Indeed my test works with 3.4.0-SNAPSHOT 🥳. Anyway, may I ask you a question if this (dummy) code is the correct way to got when setting up containers with dependencies and also using dynamic properties from the containers for the application context? I found a lot of different ways, but that one would look like the most "spring-ish" way to me: @TestConfiguration
public class MyContainerConfig {
@Bean
Network dockerNetwork() {
return Network.newNetwork();
}
@Bean
@ServiceConnection
@Primary
PostgreSQLContainer<?> postgresContainer(Network network) {
return new PostgreSQLContainer<>(DockerImageName.parse("postgres:16-alpine"))
// ... more options ...
;
}
@Bean
@DependsOn({"postgresContainer"})
KeycloakContainer keycloakContainer(Network network) {
return new KeycloakContainer()
// ... more options ...
;
}
@Bean
DynamicPropertyRegistrar keycloakPropertiesRegistrar(KeycloakContainer container) {
return registry -> {
// add dynamic keycloak properties to application context
registry.add("my.keycloak-admin.url", container::getAuthServerUrl);
// ... more properties ...
};
}
} |
Yes, as of 3.4 (only in 3.4.0-SNAPSHOT at the moment), that's the preferred way to do it. Specifically, when containers are defined as beans, using a Thanks very much for trying out the snapshot and letting us know things are working again. I'll close this one as a duplicate of #41996. |
After upgrading a Spring Boot 3.3.4 project to Spring Boot 3.4-M3 i encountered a changed behaviour when defining two TestContainer beans that depend on each other and using a third (ServletFilter) Bean that (indirectly) consumes the application's
DataSource
.Reproducible setup
Container
beans in my@TestConfiguration
class. One of them providing theServiceConnection
for my DataSource.@DependsOn
annotation to mark a dependency on the other container:@Bean
method that registeres a ServletFilter-Bean. The methods expects aJdbcClient
as parameterJdbcClient
is not really used here (as opposed to my real application), but it's enough just to add it here as a method param to make the application start failingChanged Behaviour
I have created a repository with two versions of the same application for Spring Boot 3.3 and 3.4. The only difference is the pom.xml-file: https://github.com/nilshartmann/testcontainer-example
You can see the problem when running the
TestcontainerExampleApplicationTests
in both3_3
and3_4
subfolders.If you either remove the
@DependsOn
annotation or remove theJdbcClient
from thefilterOne
method the application starts (unfortunately in my real application I cannot remove one of this two...).Thanks for any help!
The text was updated successfully, but these errors were encountered: