-
Notifications
You must be signed in to change notification settings - Fork 40.9k
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
Testcontainers support for various containers does not work in a native-image #36606
Comments
This comment was marked as outdated.
This comment was marked as outdated.
The git repo is available at https://github.com/magnus-larsson/sb312-tc-native-bug. I noted that the issue is marked with |
Hey @magnus-larsson, sorry for taking my time to look at this issue. Thanks for the report and for the reproducer. You don't need to provide more information, we have everything we need. I can reproduce this. The 3 registrations are returned in
but this call always returns
On the JVM this works for the |
The |
Until we fix this, you can use this workaround: @ImportRuntimeHints(MyHints.class)
public abstract class MongoDbTestBase {
// ... snip ...
static class MyHints implements RuntimeHintsRegistrar {
@Override
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
hints.reflection().registerType(TypeReference.of("com.mongodb.ConnectionString"));
}
}
} |
It looks like Spring Boot 3.1.4 solved this issue. I don't need the workaround described above to make nativeTests work after upgrading to Spring Boot 3.1.4. |
Thanks for the update, @magnus-larsson. I'm surprised that it works for you with Spring boot 3.1.4. As far as I can tell, nothing is generating the reflection hint for Updating
I think we still need to contribute a hint here. |
Looking at the code, I think the factories for Neo4j, Redis, and Zipkin as well as the various different R2DBC factories are also affected. |
@wilkinsona: You are right; I tested it on another project. Native tests still fail in the |
I think this has caused #38392. |
I have put together a minimal example that demonstrates how the use of the
@ServiceConnection
annotation with Spring Boot 3.1.2 and testcontainers breaks native tests.When running
./gradlew nativeTest
, I get the following error:To reproduce the problem, run the following commands:
To workaround the problem, do the following:
src/test/java/se/magnus/microservices/core/product/MongoDbTestBase.java
@ServiceConnection
setProperties
that is annotated with@DynamicPropertySource
With these changes in place, both
./gradlew test
and./gradlew nativeTest
works as expected.The text was updated successfully, but these errors were encountered: