I created an example project to test vibur data source support in Spring Boot 3.5.0-M1, but when I tried to use the Spring Boot Testconatiners to test the repository bean, it did not work.
The default profile is configured to run the application with a docker-compose file manually.
My Repository test is here, https://github.com/hantsy/spring6-sandbox/blob/master/boot-vibur-dbcp/src/test/java/com/example/demo/ProductRepositoryTest.java and in the test
profile based application-test.properties, I have set all connection details to null.
But when running the test, it seems Spring test containers @ServiceConnection
did not fill the connection details into properties at runtime as with other autoconfigured datasource pools, eg. HiariKu.
BTW, I also tried the classic testcontainers and DynamicPropertiesRegitery
in the ViburDataSourceTest
, and it worked well.
Comment From: wilkinsona
Your DataSourceConfig
isn't using org.springframework.boot.autoconfigure.jdbc.JdbcConnectionDetails
so the service connection information that's created by @ServiceConnection
is being ignored. You need to update your DataSource
@Bean
method to optionally consume JdbcConnectionDetails
(ObjectProvider<JdbcConnectionDetails>
) and use them when available.
Comment From: hantsy
@wilkinsona Thanks for your suggestion.
I have updated the DatasourceConfig
and tried to read the connection details like this https://github.com/hantsy/spring6-sandbox/blob/master/boot-vibur-dbcp/src/main/java/com/example/demo/DataSourceConfig.java#L25-L35, but it seems the JdbcConnectionDetails
is not available. I am sure when running ProductRepositoryTest
, the Testcontainers Postgres docker instance is started in the console.
Comment From: wilkinsona
You can't set a property to null in application.properties
. What you've done instead is set them to the string "null"
. This means that you're still ignoring the JdbcConnectionDetails
. If the connection details are available, you should use them instead of the properties as they are intended to override any property-based configuration.
Please take some time to step through your code in a debugger and observe how it's behaving before opening an issue or commenting on an existing issue. If you do so, you should see that the dataSourceProperties.getUrl() == null
if-block is never entered for the reason described above.
Comment From: hantsy
Yes, it is resolved as "null"
in the properties. I have not debugged this in IDE.
But what confused me it still started a Testcontainers Postgers service when running the test. According to the service connection conventions, when the URL is set, the service should be skipped. When I saw the Postgres service running, I thought it always overrides the properties in application.properties.
Comment From: wilkinsona
I have not debugged this in IDE.
Please do so before reporting an issue. We're a small team and we do not have time to perform initial debugging and problem diagnosis for all of Spring Boot's users.
Furthermore, I've just noticed that you also posted this on Stack Overflow. Please be more respectful of the community's time and refrain from cross-posting like this in the future. As has happened here, it often results in duplicated effort and wasted time.