admin管理员组文章数量:1307835
I created an example project to try vibur DBCP support in the Spring 3.5.0-M1, it adds Web, JDBC API, TestContainers, Postgres as dependencies, and use Java 21 and Maven to build the project.
The example project can be found here,
Currently, vibur support only exists in the DataSourceBuilder
, there is no autoconfiguration like other db pools.
There is a generated Postgres test containers config file which configured a Postges docker instance for dev/test stages.
The DemoApplication
class is a startup entry for the application with the generated Postgres instance and empty configuration of connection details(url/username/password
), it picked up the default Hiariku pool, and worked well.
@TestConfiguration(proxyBeanMethods = false)
class TestcontainersConfiguration {
@Bean
@ServiceConnection
PostgreSQLContainer<?> postgresContainer() {
return new PostgreSQLContainer<>(DockerImageName.parse("postgres:latest"))
.withExposedPorts(5432);
}
}
And ViburDataSourceTest
use traditional Testcontainers annotations and setup the connection details by Spring DynamicPropertyRegistry
, also worked well.
My problem is switching to the newly configured vibur-based DataSource
configured with DataSourceBuilder
, there is an example for testing Repository
- ProductRepository
, without the connection URL, etc, it should start the postgres and configure the connection details, but it does not work at all.
# application-test.properties
#spring.datasource.url=jdbc:postgresql://localhost:5432/testdb
#spring.datasource.username=user
#spring.datasource.password=password
spring.datasource.driver-class-name=.postgresql.Driver
logging.level.vibur=DEBUG
The Postgres test containers service did not configure the connection details as expected, the following items failed with null values.
@Test
void testDataSource() {
log.debug("Test dataSourceProperties: url={}, username={}, password={}, driverClassName={}",
dataSourceProperties.getUrl(),
dataSourceProperties.getUsername(),
dataSourceProperties.getPassword(),
dataSourceProperties.getDriverClassName());
assertThat(dataSourceProperties.getUrl()).isNotNull();
assertThat(dataSourceProperties.getUsername()).isNotNull();
assertThat(dataSourceProperties.getPassword()).isNotNull();
}
Compared to the DemoApplication
which used the same Postgres test containers config but used the default HiariKu pool, it started successfully.
本文标签: DataSourceBuilder and Spring TestcontainersStack Overflow
版权声明:本文标题:DataSourceBuilder and Spring Testcontainers - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741847140a2400847.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论