The HikariDataSource
dataSource
method in the DataSourceConfiguration
class uses the annotation @ConfigurationProperties(prefix = "spring.datasource.hikari")
, but the annotation used by DataSourceProperties
is @ConfigurationProperties(prefix = "spring.datasource");
If yml does not write spring-datasource-url
, an error occurs. But spring:datasource:hikari: jdbc-url
already provides url
Comment From: amoswxz
Comment From: philwebb
I'm not totally sure I'm understanding the issue as it's being reported. The spring.datasource
properties are general purpose properties that apply to all datasource types. The spring.datasource.hikari
properties are specific to Hikari.
If you specify spring.datasource.url
in your yaml it should be applied to Hikari (see this line of DataSourceBuilder).
Can you please clarify the problem that you're seeing and ideally provide a small sample that replicates it?
Comment From: amoswxz
Hikaricp provides the spring-datasource-jdbc-url, why use a spring-datasource-url, otherwise it will error
@philwebb
Comment From: philwebb
I'm sorry. I'm still not following. What error are you seeing? Please provide a sample.
Comment From: amoswxz
Do you think the url in the red box can be removed?
@philwebb
Comment From: snicoll
@amoswxz are you configuring the datasource yourself? If you are then it might help saying that because that's a different problem that is covered in the documentation.
If you don't, sharing screenshots is not helping I am afraid and sharing a sample we can run ourselves that exhibits the problem you are describing would help us.
Comment From: amoswxz
Sorry, I have expressed some problems。 Configure hikaricp in yaml:
spring:
datasource:
hikari:
jdbc-url: jdbc:mysql:/xxxx/amos?autoReconnect=true&useSSL=false
username:xxx
password: xxx
driver-class-name: com.mysql.jdbc.Driver
This configuration is wrong;Because of missing spring-datasource-url configuration @snicoll
Comment From: bclozel
Please share a minimal sample application that we can git clone or download, and that reproduces the issue you’re having. This is the most efficient way to move forward with this - more comments won’t really help I’m afraid.
Thanks!
Comment From: snicoll
@amoswxz also, if that helps, spring.datasource.hikari
properties are meant for advanced customizations of the pool. Basic settings such as url, username/password, etc should be specified with spring.datasource
. It looks like you are mixing the two (which you shouldn't). As Brian pointed out, we don't understand the problem you are reporting so please share a sample we can run that demonstrates it.
Comment From: amoswxz
@snicoll I probably understand what you mean. Configure user name password, jdbc-url, should use spring-datasource, should not use spring-datasource-hikari to configure jdbc-url?
Comment From: snicoll
If you are using the auto-configuration, then you should read the related section in the reference documentation that states that,
You should at least specify the URL by setting the spring.datasource.url property
The argument is that the standard options will still work even if you switch to a different connection pool. Your configuration above is incorrect as a central piece of the datasource is configured with a connection poll specific setting.
All in all, the connection-pool specific namespace is meant to configure advanced options. The url of the datasource is not an advanced option. There is no reason to start configuring things in two different places. If that's what you want, please create your own DataSource
bean and do not use the auto-configuration.
Comment From: amoswxz
thanks
Comment From: amoswxz
What I don't understand is why this is the design. Spring-datasource-url already exists, why spring-datasource-hikaricp-url. Thank you @snicoll
Comment From: EmielSito
What I don't understand is why this is the design. Spring-datasource-url already exists, why spring-datasource-hikaricp-url
@amoswxz I'm not 100% sure but I believe it is because Spring-datasource-url is the default usage. and if you use spring-datasource-hikaricp-url it means you are going past the default usage and into advanced usage. basically spring-datasource-hikaricp-url will override Spring-datasource-url because now you are configuring things yourself ( advanced mode)
@snicoll Thumbs up if this is the correct understanding ( in simple terms) ?
Comment From: snicoll
It's a bit more complicated than that. spring.datasource.hikari.*
is used to configure advanced settings of Hikari as you've mentioned and above all connection pool specific settings.
spring.datasource.*
is guaranteed to work with the connection pools that we support. So you set the url, password, etc there and depending on the supported connection pool on the classpath, we auto-configure it with that information.
Now the problem of the question @amoswxz was asking is that when we expose the settings for HikariDataSource
we do expose the bean as a whole and we have no way to "remove" settings that are duplicate. It's a limitation and I agree it can be confusing.
Comment From: jianglin1008
@ConfigurationProperties(prefix = "spring.datasource.hikari")
working as expected?
Comment From: snicoll
@jianglin1008 please ask questions on Stackoverflow.