Guys, I got the following properties to work, kind of. The following creates 2 pools. One connection, in the first pool, and then 20 in the second.
spring.jpa.properties.hibernate.hikari.minimumIdle = 20spring.jpa.properties.hibernate.hikari.maximumPoolSize = 30spring.jpa.properties.hibernate.hikari.idleTimeout = 5000spring.jpa.properties.hibernate.hikari.dataSource.serverName = serverspring.jpa.properties.hibernate.hikari.dataSource.portNumber = 50000spring.jpa.properties.hibernate.hikari.dataSource.databaseName = dbspring.jpa.properties.hibernate.hikari.dataSource.clientProgramName=appnamespring.jpa.properties.hibernate.hikari.dataSource.currentSchema=schemaspring.jpa.properties.hibernate.hikari.dataSource.user=userspring.jpa.properties.hibernate.hikari.dataSource.password=pwdspring.jpa.properties.hibernate.hikari.dataSourceClassName=com.ibm.db2.jcc.DB2SimpleDataSourcespring.jpa.properties.hibernate.hikari.dataSource.driverType=4spring.jpa.properties.hibernate.connection.provider_class = org.hibernate.hikaricp.internal.HikariCPConnectionProviderspring.datasource.url=jdbc:db2://server:50000/dbspring.datasource.username=userspring.datasource.password=pwd
https://github.com/brettwooldridge/HikariCP/issues/604
29.1.2 Connection to a production database
Production database connections can also be auto-configured using a pooling DataSource
. Here’s the algorithm for choosing a specific implementation:
- 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.
If you use the spring-boot-starter-jdbc
or spring-boot-starter-data-jpa
‘starters’ you will automatically get a dependency to tomcat-jdbc
.
http://docs.spring.io/spring-boot/docs/1.4.3.RELEASE/reference/htmlsingle/#using-boot-running-with-the-gradle-plugin
You can use the dataSourceClassName approach, here is an example with MySQL. (Tested with spring boot 1.3 and 1.4)
First you need to exclude tomcat-jdbc from the classpath as it will be picked in favor of hikaricp.
org.springframework.boot spring-boot-starter-jdbc org.apache.tomcat tomcat-jdbc
application.properties
spring.datasource.dataSourceClassName=com.mysql.jdbc.jdbc2.optional.MysqlDataSourcespring.datasource.dataSourceProperties.serverName=localhostspring.datasource.dataSourceProperties.portNumber=3311spring.datasource.dataSourceProperties.databaseName=mydbspring.datasource.username=rootspring.datasource.password=root
@Bean@ConfigurationProperties(prefix = "spring.datasource")public DataSource dataSource() { return DataSourceBuilder.create().build();}
I created a test project here:
ApplicationContext ctx = SpringApplication.run(Application.class, args); DataSource datasource = ctx.getBean(DataSource.class); System.out.println(datasource.getClass().getCanonicalName());
https://github.com/ydemartino/spring-boot-hikaricp
my test java config (for MySql)
@Bean(destroyMethod = "close")public DataSource dataSource(){ HikariConfig hikariConfig = new HikariConfig(); hikariConfig.setDriverClassName("com.mysql.jdbc.Driver"); hikariConfig.setJdbcUrl("jdbc:mysql://localhost:3306/spring-test"); hikariConfig.setUsername("root"); hikariConfig.setPassword("admin"); hikariConfig.setMaximumPoolSize(5); hikariConfig.setConnectionTestQuery("SELECT 1"); hikariConfig.setPoolName("springHikariCP"); hikariConfig.addDataSourceProperty("dataSource.cachePrepStmts", "true"); hikariConfig.addDataSourceProperty("dataSource.prepStmtCacheSize", "250"); hikariConfig.addDataSourceProperty("dataSource.prepStmtCacheSqlLimit", "2048"); hikariConfig.addDataSourceProperty("dataSource.useServerPrepStmts", "true"); HikariDataSource dataSource = new HikariDataSource(hikariConfig); return dataSource;}
http://stackoverflow.com/questions/23172643/how-to-set-up-datasource-with-spring-for-hikaricp