-
Notifications
You must be signed in to change notification settings - Fork 41k
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
H2ConsoleAutoConfiguration causes early initialization of DataSource beans #43337
Comments
It's hard to say for sure what's happening as there are some parts of your app that you haven't shared. For example, we can't see how the |
Hello @wilkinsona, thank you for looking into the issue. While creating a minimal example to reproduce the error, I discovered that the cause of the problem was having the dependency I'm not sure if this behavior is intentional or not. If you'd like, I have a small project where the issue can be reproduced. |
Yes please, @AlbertoCortina. |
Here is the repository -> https://github.com/AlbertoCortina/demo-bug-testcontainers-dynamicpropertysource To reproduce the error just try to run the application in the Please let me know if you don't manage to reproduce the error |
Thanks for the sample, this appears to be because the spring:
h2:
console:
enabled: false |
Context
I have an application (recently upgraded to Spring Boot 3.4.0) with two configured data sources, following a setup similar to the one described in this Baeldung article.
Currently, I am using Testcontainers for integration tests, based on the approach outlined in Spring Boot's documentation. These tests mock the second data source, and everything is working perfectly.
After a great initial experience using Testcontainers for testing, I decided to try it for local development. However, this is where I encountered some challenges.
Problem
I followed the steps described in Baeldung's article on Testcontainers support for local development and Spring's blog post on improved Testcontainers support in Spring Boot 3.1.
Below are the classes involved:
When running the application, I noticed that the data source configuration is executed before the
@DynamicPropertySource
, which results in the application picking up the properties defined in my application.yml.In contrast, during an integration test, the behavior is reversed: the values from the
@DynamicPropertySource
are processed first, and only then is the data source configured.Is this the expected behavior, or could it be a bug when using Testcontainers for local development?
Please let me know if anything is unclear.
Thank you very much!
The text was updated successfully, but these errors were encountered: