Spring Boot Hikari
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 = 20
spring.jpa.properties.hibernate.hikari.maximumPoolSize = 30
spring.jpa.properties.hibernate.hikari.idleTimeout = 5000
spring.jpa.properties.hibernate.hikari.dataSource.serverName = server
spring.jpa.properties.hibernate.hikari.dataSource.portNumber = 50000
spring.jpa.properties.hibernate.hikari.dataSource.databaseName = db
spring.jpa.properties.hibernate.hikari.dataSource.clientProgramName=appname
spring.jpa.properties.hibernate.hikari.dataSource.currentSchema=schema
spring.jpa.properties.hibernate.hikari.dataSource.user=user
spring.jpa.properties.hibernate.hikari.dataSource.password=pwd
spring.jpa.properties.hibernate.hikari.dataSourceClassName=com.ibm.db2.jcc.DB2SimpleDataSource
spring.jpa.properties.hibernate.hikari.dataSource.driverType=4
spring.jpa.properties.hibernate.connection.provider_class = org.hibernate.hikaricp.internal.HikariCPConnectionProvider spring.datasource.url=jdbc:db2://server:50000/db
spring.datasource.username=user
spring.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
DataSourcefor 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.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jdbc</artifactId>
</exclusion>
</exclusions>
</dependency>
application.properties
spring.datasource.dataSourceClassName=com.mysql.jdbc.jdbc2.optional.MysqlDataSource
spring.datasource.dataSourceProperties.serverName=localhost
spring.datasource.dataSourceProperties.portNumber=3311
spring.datasource.dataSourceProperties.databaseName=mydb
spring.datasource.username=root
spring.datasource.password=root
@Bean
@ConfigurationProperties(prefix = "spring.datasource")
public DataSource dataSource() {
return DataSourceBuilder.create().build();
}
I created a test project here: https://github.com/ydemartino/spring-boot-hikaricp
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
Spring Boot Hikari的更多相关文章
- Spring Boot (三): ORM 框架 JPA 与连接池 Hikari
前面两篇文章我们介绍了如何快速创建一个 Spring Boot 工程<Spring Boot(一):快速开始>和在 Spring Boot 中如何使用模版引擎 Thymeleaf 渲染一个 ...
- Spring Boot 2.x基础教程:默认数据源Hikari的配置详解
通过上一节的学习,我们已经学会如何应用Spring中的JdbcTemplate来完成对MySQL的数据库读写操作.接下来通过本篇文章,重点说说在访问数据库过程中的一个重要概念:数据源(Data Sou ...
- spring boot:使用mybatis访问多个mysql数据源/查看Hikari连接池的统计信息(spring boot 2.3.1)
一,为什么要访问多个mysql数据源? 实际的生产环境中,我们的数据并不会总放在一个数据库, 例如:业务数据库:存放了用户/商品/订单 统计数据库:按年.月.日的针对用户.商品.订单的统计表 因为统计 ...
- 玩转spring boot——properties配置
前言 在以往的java开发中,程序员最怕大量的配置,是因为配置一多就不好统一管理,经常出现找不到配置的情况.而项目中,从开发测试环境到生产环境,往往需要切换不同的配置,如测试数据库连接换成生产数据库连 ...
- Spring Boot MyBatis 连接数据库
最近比较忙,没来得及抽时间把MyBatis的集成发出来,其实mybatis官网在2015年11月底就已经发布了对SpringBoot集成的Release版本,Github上有代码:https://gi ...
- (转) Spring Boot MyBatis 连接数据库
最近比较忙,没来得及抽时间把MyBatis的集成发出来,其实mybatis官网在2015年11月底就已经发布了对SpringBoot集成的Release版本,Github上有代码:https://gi ...
- 四、Spring Boot 多数据源 自动切换
实现案例场景: 某系统除了需要从自己的主要数据库上读取和管理数据外,还有一部分业务涉及到其他多个数据库,要求可以在任何方法上可以灵活指定具体要操作的数据库.为了在开发中以最简单的方法使用,本文基于注解 ...
- 二、spring Boot构建的Web应用中,基于MySQL数据库的几种数据库连接方式进行介绍
包括JDBC.JPA.MyBatis.多数据源和事务. 一.JDBC 连接数据库 1.属性配置文件(application.properties) spring.datasource.url=jdbc ...
- springboot2.0(一):【重磅】Spring Boot 2.0权威发布
就在昨天Spring Boot2.0.0.RELEASE正式发布,今天早上在发布Spring Boot2.0的时候还出现一个小插曲,将Spring Boot2.0同步到Maven仓库的时候出现了错误, ...
随机推荐
- WinCE系统声音定制
作者:ARM-WinCE 2010的第一篇Blog,介绍一下WinCE系统声音的定制.说白了,就是设置注册表.WinCE系统启动的开机音乐,点击触摸屏以及键盘输入的按键音,还有系统运行过程中的各种声音 ...
- Hbase replication操作
1.修改hbase-site.xml文件 <property> <name>hbase.replication</name> <value>true ...
- winform编程设定listview选中行
在做项目中,需要用到listview显示数据.同时,项目要求,通过检索用户输入的数据,程序通过搜索,确定数据所在的行并通过程序设定为选中状态并高亮显示.同时,正常响应鼠标单击响应的效果,单击时,程序设 ...
- glib-dbus 在ubuntu9.10 和 ubuntu10.04 上安装环境的搭建
dbus-glib 安装环境搭建 安装 dbus apt-get install dbus 安装 d-feet ,用于查看 session bus 和 system bus apt-get insta ...
- AndroidUI之绘图机制和原理 最完整的文章
转载请标明出处:http://blog.csdn.net/sk719887916/article/details/39961171,作者:skay 导读: 熟悉javaGUI的朋友对java绘图必定 ...
- SharePoint 2007 图片库视图不可用、页面标题不显示
描述: 问题1:SharePoint新建图片库,想选择"视图"-"所有图片",选择"详细信息.幻灯片.缩略图"等视图,均没有反应.如图1. ...
- 熊猫猪新系统测试之二:Mac OS X 10.10 优胜美地
在第一篇windows 10技术预览版测试之后,本猫为大家呈现另一个刚刚才更新的mac操作系统:"优胜美地".苹果同样一改以猫科动物为代号命名的传统,在10.9的Mavericks ...
- wait和notify的理解与使用
1.对于wait()和notify()的理解 对于wait()和notify()的理解,还是要从jdk官方文档中开始,在Object类方法中有: void notify() Wakes up a si ...
- 模拟IC芯片设计开发的流程
模拟IC芯片设计开发的流程 IC的设计,模拟和数字, 还有混合IC, 在设计方法, 注意点, 工具等有明显的区别, 我主要以模拟无线接收IC系统设计为例说明. 一个IC芯片的设计开发大致包括如下步骤. ...
- java并发容器(Map、List、BlockingQueue)
转发: 大海巨浪 Java库本身就有多种线程安全的容器和同步工具,其中同步容器包括两部分:一个是Vector和Hashtable.另外还有JDK1.2中加入的同步包装类,这些类都是由Collectio ...