user5620472
user5620472

Reputation: 2882

what is right? dbcp/dbcp2/tomcat validation-query

I need create connection reconect in Spring boot. Many examples shows like this:

spring.datasource.validationQuery=SELECT 1

but Intellij IDE not see ths and shows:

spring.datasource.dbcp.validation-query=select 1

and

spring.datasource.dbcp2.validation-query=select 1 

and

spring.datasource.tomcat.validation-query=select 1

what is right?

Upvotes: 4

Views: 1993

Answers (1)

Dimitri Mestdagh
Dimitri Mestdagh

Reputation: 44725

Before Spring 1.4, all connection pool providers (Tomcat, Apache DBCP, Apache DBCP v2, Hikari, ...) used the same properties, for example:

spring.datasource.validationQuery=select 1

Depending on the connection pool vendor, you could use different properties. Not only that, but some of those properties weren't used to configure the vendor-specific properties, but were used by Spring boot as well. So they were quite ambiguous.

Since 1.4 the Spring boot properties are within spring.datasource.* while the connection pool properties are within spring.datasource.tomcat.* or spring.datasource.dbcp.* or ... .


To answer your question, if you're using Spring boot 1.3 or less the correct answer is:

spring.datasource.validationQuery=select 1

If you're using Spring boot 1.4 or newer with the default tomcat-jdbc connection pool, the correct answer is:

spring.datasource.tomcat.validationQuery=select 1

The other options you provided are only valid if you're using Spring boot 1.4 or newer and did override the default connection pool provider.


Other than that you can choose whether or not you want to use camelcase (validationQuery) or kebab-case (validation-query), both work fine on any version of Spring boot.

Upvotes: 4

Related Questions