springboot 2.0 mariadb hikari-cp连接池

直到今天 2018年9月29日 10:00:38 ,hikari-cp 在maven 官方仓库最新版本为2.6

SpringBoot 2.0.5 控制台输出,默认的是 2.7.9 

spring-boot-starter-jdbc\2.0.5.RELEASE\spring-boot-starter-jdbc-2.0.5.RELEASE.jar;H:\localRepository\com\zaxxer\HikariCP\2.7.9\HikariCP-2.7.9.jar;

 

pom.xml

xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0modelVersion>

    <groupId>org.lzwgroupId>
    <artifactId>hikaricpartifactId>
    <version>0.0.1-SNAPSHOTversion>
    <packaging>jarpackaging>

    <name>hikaricpname>
    <description>hikaricp for Spring Bootdescription>

    <parent>
        <groupId>org.springframework.bootgroupId>
        <artifactId>spring-boot-starter-parentartifactId>
        <version>2.0.5.RELEASEversion>
        <relativePath/> 
    parent>

    <properties>
        <project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8project.reporting.outputEncoding>
        <java.version>1.8java.version>
    properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starterartifactId>
        dependency>

        
        <dependency>
            <groupId>org.mariadb.jdbcgroupId>
            <artifactId>mariadb-java-clientartifactId>
            <version>2.3.0version>
        dependency>

        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-data-jpaartifactId>
        dependency>

        
        <dependency>
            <groupId>org.mybatis.spring.bootgroupId>
            <artifactId>mybatis-spring-boot-starterartifactId>
            <version>1.3.2version>
        dependency>

        <dependency>
            <groupId>org.lzwgroupId>
            <artifactId>jbatisartifactId>
            <version>1.0version>
        dependency>

        <dependency>
            <groupId>org.projectlombokgroupId>
            <artifactId>lombokartifactId>
            <optional>trueoptional>
        dependency>

        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-testartifactId>
            <scope>testscope>
        dependency>

    dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.bootgroupId>
                <artifactId>spring-boot-maven-pluginartifactId>
            plugin>
        plugins>
    build>


project>

application.yml

spring:
  datasource:
    driver-class-name: org.mariadb.jdbc.Driver
    url: jdbc:mysql://192.168.91.137:3306/sharding_test?serverTimezone=Hongkong&useUnicode=true&characterEncoding=UTF-8&useSSL=false
    type: com.zaxxer.hikari.HikariDataSource
    hikari:
#      driver-class-name: org.mariadb.jdbc.Driver
#      jdbc-url: jdbc:mysql://192.168.91.137:3306/sharding_test?serverTimezone=Hongkong&useUnicode=true&characterEncoding=UTF-8&useSSL=false
      username: root
      password: root
      minimum-idle: 5
      maximum-pool-size: 50
      auto-commit: true
      idle-timeout: 30000
      pool-name: HikariCpExample
      max-lifetime: 1800000
      connection-timeout: 30000
      connection-test-query: SELECT 1

  jpa:
    show-sql: true
    database-platform: org.hibernate.dialect.MariaDB103Dialect

 

单元测试

/**
 * @author laizhenwei
 * @date 2018/09/29
 */
@RunWith(SpringRunner.class)
@SpringBootTest
public class ShardingEntityServiceTest {

    @Resource
    private ShardingEntityService shardingEntityService;

    @Test
    public void addTests(){
        shardingEntityService.save(new ShardingEntity().setOrgId(1L).setData("1"));
    }

}

 

转载于:https://www.cnblogs.com/sweetchildomine/p/9722165.html

你可能感兴趣的:(springboot 2.0 mariadb hikari-cp连接池)