Reputation: 30076
In org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration
:
@Bean
@ConfigurationProperties(prefix = "spring.datasource.hikari")
public HikariDataSource dataSource(DataSourceProperties properties) {
HikariDataSource dataSource = createDataSource(properties, HikariDataSource.class);
if (StringUtils.hasText(properties.getName())) {
dataSource.setPoolName(properties.getName());
}
return dataSource;
}
The parameter type DataSourceProperties
lacks many of the properties that is supported by the target type HikariDataSource
(e.g. maximum-pool-size
and many others) (aparently by design). and hence many of the properties is not passed as documented in : spring-configuration-metadata.json
{
"name": "spring.datasource.hikari.auto-commit",
"type": "java.lang.Boolean",
"sourceType": "com.zaxxer.hikari.HikariDataSource"
},
{
"name": "spring.datasource.hikari.catalog",
"type": "java.lang.String",
"sourceType": "com.zaxxer.hikari.HikariDataSource"
}
So should I define the dataasource bean and set the properties to HikariDataSource
so what is the point of having properties such as the above (spring.datasource.hikari.auto-commit
... etc) the as part of the autoconfiguration properties?
Upvotes: 0
Views: 472
Reputation: 5182
The HikariDataSource
extends HikariConfig
, which has all the additional properties you would want to set.
Spring will bind any property with the prefix spring.datasource.hikari
into the DataSource
directly, not into the DataSourceProperties
object.
It is done by using ConfigurationPropertiesBindingPostProcessor
in a later stage.
Upvotes: 1