博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Spring Boot Hikari
阅读量:5900 次
发布时间:2019-06-19

本文共 4381 字,大约阅读时间需要 14 分钟。

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

 

转载于:https://www.cnblogs.com/softidea/p/6344041.html

你可能感兴趣的文章
angular2.0学习笔记1.开发环境搭建 (node.js和npm的安装)
查看>>
.bashrc和.bash_profile的区别
查看>>
让你的PHP程序真正的实现多线程(PHP多线程类)(转)
查看>>
search-a-2d-matrix——二维矩阵找数
查看>>
lua基础【三】唯一数据结构table表
查看>>
Web应用安全审计工具WATOBO
查看>>
CSS3_animation笔记
查看>>
Android Google 地图 API for Android
查看>>
从 Zero 到 Hero ,一文掌握 Python--转
查看>>
【软件下载】整理一些外国的工具软件下载到网盘方便国内使用
查看>>
idea项目左边栏只能看到文件看不到项目结构
查看>>
idea如何编译maven项目
查看>>
在centos7下安装svn
查看>>
删除软链接
查看>>
windows7下MSN如何最小化到任务栏
查看>>
HDU-3016 Man Down 线段树
查看>>
初步认识注册表(待续)
查看>>
只能输入数字的TextBox自定义控件
查看>>
自定义事件
查看>>
浮点数的二进制
查看>>