Reputation: 1340
Recently I migrated to latest spring-boot version(1.4.2) . I observered few of the old properties are more supported.
Old configuration
spring.datasource.max-active=1
spring.datasource.validation-query=/* ping */ SELECT 1
spring.datasource.test-on-borrow=true
spring.datasource.initial-size=1
New Configuration
spring.datasource.dbcp.max-active=1
spring.datasource.dbcp.validation-query=/* ping */ SELECT 1
spring.datasource.dbcp.test-on-borrow=true
spring.datasource.dbcp.initial-size=1
After migrating to the new configuration, My application is still consuming 10 connection which is a default configuration.
What are the additional configuration am I missing?
Upvotes: 2
Views: 5313
Reputation: 44715
According to the documentation, by default, Spring boot uses Tomcat JDBC. It is also included by default into spring-boot-starter-jdbc which is included in spring-boot-starter-data-jpa.
- We prefer the Tomcat pooling DataSource for its performance and concurrency, so if that is available we always choose it.
- Otherwise, if HikariCP is available we will use it.
- If neither the Tomcat pooling datasource nor HikariCP are available and if Commons DBCP is available we will use it, but we don’t recommend it in production.
- Lastly, if Commons DBCP2 is available we will use it.
This means that you should be using the spring.datasource.tomcat.*
properties, for example:
spring.datasource.tomcat.max-active=1
spring.datasource.tomcat.validation-query=/* ping */ SELECT 1
spring.datasource.tomcat.test-on-borrow=true
spring.datasource.tomcat.initial-size=1
Alternatively, if you prefer DBCP, you can do so by defining spring.datasource.type
property and provide the fully qualified name of the connection pool implementation. In this case, you'll have to use maxTotal
though, because maxActive
does not exist according to the documentation of DBCP.
Remember to add the right version of DBCP to your classpath though. If you're adding 1.x, you can use the spring.datasource.dbcp.*
properties (like you used), however, if you're using 2.x you should use the spring.datasource.dbcp2.*
properties:
# Commons DBCP 1.x
spring.datasource.dbcp.max-total=1
spring.datasource.dbcp.validation-query=/* ping */ SELECT 1
spring.datasource.dbcp.test-on-borrow=true
spring.datasource.dbcp.initial-size=1
spring.datasource.type=org.apache.commons.dbcp.BasicDataSource # To override the default classpath lookup behaviour
# Commons DBCP 2.x
spring.datasource.dbcp2.max-total=1
spring.datasource.dbcp2.validation-query=/* ping */ SELECT 1
spring.datasource.dbcp2.test-on-borrow=true
spring.datasource.dbcp2.initial-size=1
spring.datasource.type=org.apache.commons.dbcp2.BasicDataSource # To override the default classpath lookup behaviour
Upvotes: 6