mirror of
https://gitee.com/yudaocode/SpringBoot-Labs.git
synced 2026-09-03 05:53:54 +08:00
增加连接池示例
This commit is contained in:
47
lab-19/lab-19-datasource-pool-druid-multiple/pom.xml
Normal file
47
lab-19/lab-19-datasource-pool-druid-multiple/pom.xml
Normal file
@@ -0,0 +1,47 @@
|
||||
<?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">
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.1.3.RELEASE</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>lab-19-datasource-pool-druid-multiple</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<!-- 保证 Spring JDBC 的依赖健全 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-jdbc</artifactId>
|
||||
</dependency>
|
||||
<!-- 实现对 Druid 连接池的自动化配置 -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid-spring-boot-starter</artifactId>
|
||||
<version>1.1.21</version>
|
||||
</dependency>
|
||||
<dependency> <!-- 本示例,我们使用 MySQL -->
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>5.1.48</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 实现对 Spring MVC 的自动化配置,因为我们需要看看 Druid 的监控功能 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 方便等会写单元测试 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,49 @@
|
||||
package cn.iocoder.springboot.lab19.datasourcepool;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
|
||||
@SpringBootApplication
|
||||
public class Application implements CommandLineRunner {
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(Application.class);
|
||||
|
||||
@Resource(name = "ordersDataSource")
|
||||
private DataSource ordersDataSource;
|
||||
|
||||
@Resource(name = "usersDataSource")
|
||||
private DataSource usersDataSource;
|
||||
|
||||
public static void main(String[] args) {
|
||||
// 启动 Spring Boot 应用
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(String... args) {
|
||||
// orders 数据源
|
||||
try (Connection conn = ordersDataSource.getConnection()) {
|
||||
// 这里,可以做点什么
|
||||
logger.info("[run][ordersDataSource 获得连接:{}]", conn);
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
// users 数据源
|
||||
try (Connection conn = usersDataSource.getConnection()) {
|
||||
// 这里,可以做点什么
|
||||
logger.info("[run][usersDataSource 获得连接:{}]", conn);
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package cn.iocoder.springboot.lab19.datasourcepool.config;
|
||||
|
||||
import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
@Configuration
|
||||
public class DataSourceConfig {
|
||||
|
||||
/**
|
||||
* 创建 orders 数据源
|
||||
*/
|
||||
@Primary
|
||||
@Bean(name = "ordersDataSource")
|
||||
@ConfigurationProperties(prefix = "spring.datasource.orders") // 读取 spring.datasource.orders 配置到 HikariDataSource 对象
|
||||
public DataSource ordersDataSource() {
|
||||
return DruidDataSourceBuilder.create().build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建 users 数据源
|
||||
*/
|
||||
@Bean(name = "usersDataSource")
|
||||
@ConfigurationProperties(prefix = "spring.datasource.users")
|
||||
public DataSource usersDataSource() {
|
||||
return DruidDataSourceBuilder.create().build();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
spring:
|
||||
# datasource 数据源配置内容
|
||||
datasource:
|
||||
# 订单数据源配置
|
||||
orders:
|
||||
url: jdbc:mysql://127.0.0.1:3306/test_orders?useSSL=false&useUnicode=true&characterEncoding=UTF-8
|
||||
driver-class-name: com.mysql.jdbc.Driver
|
||||
username: root
|
||||
password:
|
||||
# Druid 自定义配置,对应 DruidDataSource 中的 setting 方法的属性
|
||||
min-idle: 0 # 池中维护的最小空闲连接数,默认为 0 个。
|
||||
max-active: 20 # 池中最大连接数,包括闲置和使用中的连接,默认为 8 个。
|
||||
# 用户数据源配置
|
||||
users:
|
||||
url: jdbc:mysql://127.0.0.1:3306/test_users?useSSL=false&useUnicode=true&characterEncoding=UTF-8
|
||||
driver-class-name: com.mysql.jdbc.Driver
|
||||
username: root
|
||||
password:
|
||||
# Druid 自定义配置,对应 DruidDataSource 中的 setting 方法的属性
|
||||
min-idle: 0 # 池中维护的最小空闲连接数,默认为 0 个。
|
||||
max-active: 20 # 池中最大连接数,包括闲置和使用中的连接,默认为 8 个。
|
||||
# Druid 自定已配置
|
||||
druid:
|
||||
# 过滤器配置
|
||||
filter:
|
||||
stat: # 配置 StatFilter ,对应文档 https://github.com/alibaba/druid/wiki/%E9%85%8D%E7%BD%AE_StatFilter
|
||||
log-slow-sql: true # 开启慢查询记录
|
||||
slow-sql-millis: 5000 # 慢 SQL 的标准,单位:毫秒
|
||||
# StatViewServlet 配置
|
||||
stat-view-servlet: # 配置 StatViewServlet ,对应文档 https://github.com/alibaba/druid/wiki/%E9%85%8D%E7%BD%AE_StatViewServlet%E9%85%8D%E7%BD%AE
|
||||
enabled: true # 是否开启 StatViewServlet
|
||||
login-username: yudaoyuanma # 账号
|
||||
login-password: javaniubi # 密码
|
||||
47
lab-19/lab-19-datasource-pool-druid-single/pom.xml
Normal file
47
lab-19/lab-19-datasource-pool-druid-single/pom.xml
Normal file
@@ -0,0 +1,47 @@
|
||||
<?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">
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.1.3.RELEASE</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>lab-19-datasource-pool-druid-single</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<!-- 保证 Spring JDBC 的依赖健全 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-jdbc</artifactId>
|
||||
</dependency>
|
||||
<!-- 实现对 Druid 连接池的自动化配置 -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid-spring-boot-starter</artifactId>
|
||||
<version>1.1.21</version>
|
||||
</dependency>
|
||||
<dependency> <!-- 本示例,我们使用 MySQL -->
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>5.1.48</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 实现对 Spring MVC 的自动化配置,因为我们需要看看 Druid 的监控功能 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 方便等会写单元测试 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,30 @@
|
||||
package cn.iocoder.springboot.lab19.datasourcepool;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
@SpringBootApplication
|
||||
public class Application implements CommandLineRunner {
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(Application.class);
|
||||
|
||||
@Autowired
|
||||
private DataSource dataSource;
|
||||
|
||||
public static void main(String[] args) {
|
||||
// 启动 Spring Boot 应用
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(String... args) {
|
||||
logger.info("[run][获得数据源:{}]", dataSource.getClass());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package cn.iocoder.springboot.lab19.datasourcepool.controller;
|
||||
|
||||
import com.alibaba.druid.stat.DruidStatManagerFacade;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
public class DruidStatController {
|
||||
|
||||
@GetMapping("/monitor/druid/stat")
|
||||
@Deprecated
|
||||
public Object druidStat(){
|
||||
// `DruidStatManagerFacade#getDataSourceStatDataList()` 方法,可以获取所有数据源的监控数据。
|
||||
// 除此之外,DruidStatManagerFacade 还提供了一些其他方法,你可以按需选择使用。
|
||||
return DruidStatManagerFacade.getInstance().getDataSourceStatDataList();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
spring:
|
||||
# datasource 数据源配置内容,对应 DataSourceProperties 配置属性类
|
||||
datasource:
|
||||
url: jdbc:mysql://127.0.0.1:3306/test?useSSL=false&useUnicode=true&characterEncoding=UTF-8
|
||||
driver-class-name: com.mysql.jdbc.Driver
|
||||
username: root # 数据库账号
|
||||
password: # 数据库密码
|
||||
type: com.alibaba.druid.pool.DruidDataSource # 设置类型为 DruidDataSource
|
||||
# Druid 自定义配置,对应 DruidDataSource 中的 setting 方法的属性
|
||||
druid:
|
||||
min-idle: 0 # 池中维护的最小空闲连接数,默认为 0 个。
|
||||
max-active: 20 # 池中最大连接数,包括闲置和使用中的连接,默认为 8 个。
|
||||
filter:
|
||||
stat: # 配置 StatFilter ,对应文档 https://github.com/alibaba/druid/wiki/%E9%85%8D%E7%BD%AE_StatFilter
|
||||
log-slow-sql: true # 开启慢查询记录
|
||||
slow-sql-millis: 5000 # 慢 SQL 的标准,单位:毫秒
|
||||
stat-view-servlet: # 配置 StatViewServlet ,对应文档 https://github.com/alibaba/druid/wiki/%E9%85%8D%E7%BD%AE_StatViewServlet%E9%85%8D%E7%BD%AE
|
||||
enabled: true # 是否开启 StatViewServlet
|
||||
login-username: yudaoyuanma # 账号
|
||||
login-password: javaniubi # 密码
|
||||
35
lab-19/lab-19-datasource-pool-hikaricp-multiple/pom.xml
Normal file
35
lab-19/lab-19-datasource-pool-hikaricp-multiple/pom.xml
Normal file
@@ -0,0 +1,35 @@
|
||||
<?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">
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.1.3.RELEASE</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>lab-19-datasource-pool-hikaricp-multiple</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<!-- 实现对数据库连接池的自动化配置 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-jdbc</artifactId>
|
||||
</dependency>
|
||||
<dependency> <!-- 本示例,我们使用 MySQL -->
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>5.1.48</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 方便等会写单元测试 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,49 @@
|
||||
package cn.iocoder.springboot.lab19.datasourcepool;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
|
||||
@SpringBootApplication
|
||||
public class Application implements CommandLineRunner {
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(Application.class);
|
||||
|
||||
@Resource(name = "ordersDataSource")
|
||||
private DataSource ordersDataSource;
|
||||
|
||||
@Resource(name = "usersDataSource")
|
||||
private DataSource usersDataSource;
|
||||
|
||||
public static void main(String[] args) {
|
||||
// 启动 Spring Boot 应用
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(String... args) {
|
||||
// orders 数据源
|
||||
try (Connection conn = ordersDataSource.getConnection()) {
|
||||
// 这里,可以做点什么
|
||||
logger.info("[run][ordersDataSource 获得连接:{}]", conn);
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
// users 数据源
|
||||
try (Connection conn = usersDataSource.getConnection()) {
|
||||
// 这里,可以做点什么
|
||||
logger.info("[run][usersDataSource 获得连接:{}]", conn);
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package cn.iocoder.springboot.lab19.datasourcepool.config;
|
||||
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
@Configuration
|
||||
public class DataSourceConfig {
|
||||
|
||||
/**
|
||||
* 创建 orders 数据源的配置对象
|
||||
*/
|
||||
@Primary
|
||||
@Bean(name = "ordersDataSourceProperties")
|
||||
@ConfigurationProperties(prefix = "spring.datasource.orders") // 读取 spring.datasource.orders 配置到 DataSourceProperties 对象
|
||||
public DataSourceProperties ordersDataSourceProperties() {
|
||||
return new DataSourceProperties();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建 orders 数据源
|
||||
*/
|
||||
@Bean(name = "ordersDataSource")
|
||||
@ConfigurationProperties(prefix = "spring.datasource.orders.hikari") // 读取 spring.datasource.orders 配置到 HikariDataSource 对象
|
||||
public DataSource ordersDataSource() {
|
||||
// 获得 DataSourceProperties 对象
|
||||
DataSourceProperties properties = this.ordersDataSourceProperties();
|
||||
// 创建 HikariDataSource 对象
|
||||
return createHikariDataSource(properties);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建 users 数据源的配置对象
|
||||
*/
|
||||
@Bean(name = "usersDataSourceProperties")
|
||||
@ConfigurationProperties(prefix = "spring.datasource.users") // 读取 spring.datasource.users 配置到 DataSourceProperties 对象
|
||||
public DataSourceProperties usersDataSourceProperties() {
|
||||
return new DataSourceProperties();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建 users 数据源
|
||||
*/
|
||||
@Bean(name = "usersDataSource")
|
||||
@ConfigurationProperties(prefix = "spring.datasource.users.hikari")
|
||||
public DataSource usersDataSource() {
|
||||
// 获得 DataSourceProperties 对象
|
||||
DataSourceProperties properties = this.usersDataSourceProperties();
|
||||
// 创建 HikariDataSource 对象
|
||||
return createHikariDataSource(properties);
|
||||
}
|
||||
|
||||
private static HikariDataSource createHikariDataSource(DataSourceProperties properties) {
|
||||
// 创建 HikariDataSource 对象
|
||||
HikariDataSource dataSource = properties.initializeDataSourceBuilder().type(HikariDataSource.class).build();
|
||||
// 设置线程池名
|
||||
if (StringUtils.hasText(properties.getName())) {
|
||||
dataSource.setPoolName(properties.getName());
|
||||
}
|
||||
return dataSource;
|
||||
}
|
||||
|
||||
// /**
|
||||
// * 创建 orders 数据源
|
||||
// */
|
||||
// @Bean(name = "ordersDataSource")
|
||||
// @ConfigurationProperties(prefix = "spring.datasource.orders")
|
||||
// public DataSource ordersDataSource() {
|
||||
// return DataSourceBuilder.create().build();
|
||||
// }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
spring:
|
||||
# datasource 数据源配置内容
|
||||
datasource:
|
||||
# 订单数据源配置
|
||||
orders:
|
||||
url: jdbc:mysql://127.0.0.1:3306/test_orders?useSSL=false&useUnicode=true&characterEncoding=UTF-8
|
||||
driver-class-name: com.mysql.jdbc.Driver
|
||||
username: root
|
||||
password:
|
||||
# HikariCP 自定义配置,对应 HikariConfig 配置属性类
|
||||
hikari:
|
||||
minimum-idle: 20 # 池中维护的最小空闲连接数,默认为 10 个。
|
||||
maximum-pool-size: 20 # 池中最大连接数,包括闲置和使用中的连接,默认为 10 个。
|
||||
# 用户数据源配置
|
||||
users:
|
||||
url: jdbc:mysql://127.0.0.1:3306/test_users?useSSL=false&useUnicode=true&characterEncoding=UTF-8
|
||||
driver-class-name: com.mysql.jdbc.Driver
|
||||
username: root
|
||||
password:
|
||||
# HikariCP 自定义配置,对应 HikariConfig 配置属性类
|
||||
hikari:
|
||||
minimum-idle: 15 # 池中维护的最小空闲连接数,默认为 10 个。
|
||||
maximum-pool-size: 15 # 池中最大连接数,包括闲置和使用中的连接,默认为 10 个。
|
||||
@@ -1,5 +1,7 @@
|
||||
package cn.iocoder.springboot.lab19.datasourcepool;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
@@ -12,6 +14,8 @@ import java.sql.SQLException;
|
||||
@SpringBootApplication
|
||||
public class Application implements CommandLineRunner {
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(Application.class);
|
||||
|
||||
@Autowired
|
||||
private DataSource dataSource;
|
||||
|
||||
@@ -21,10 +25,10 @@ public class Application implements CommandLineRunner {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(String... args) throws Exception {
|
||||
public void run(String... args) {
|
||||
try (Connection conn = dataSource.getConnection()) {
|
||||
// 这里,可以做点什么
|
||||
System.out.println("连接:" + conn.getClass());
|
||||
logger.info("[run][获得连接:{}]", conn);
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,5 @@ spring:
|
||||
password: # 数据库密码
|
||||
# HikariCP 自定义配置,对应 HikariConfig 配置属性类
|
||||
hikari:
|
||||
minimum-idle: 10 # 池中维护的最小空闲连接数,默认为 10 个。
|
||||
maximum-pool-size: 10 # 池中最大连接数,包括闲置和使用中的连接,默认为 10 个。
|
||||
|
||||
minimum-idle: 20 # 池中维护的最小空闲连接数,默认为 10 个。
|
||||
maximum-pool-size: 20 # 池中最大连接数,包括闲置和使用中的连接,默认为 10 个。
|
||||
|
||||
@@ -12,9 +12,10 @@
|
||||
<artifactId>lab-19</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<modules>
|
||||
<module>lab-18-hikaricp-single</module>
|
||||
<module>lab-18-datasource-pool-hikaricp-single</module>
|
||||
<module>lab-19-datasource-pool-hikaricp-single</module>
|
||||
<module>lab-19-datasource-pool-hikaricp-multiple</module>
|
||||
<module>lab-19-datasource-pool-druid-single</module>
|
||||
<module>lab-19-datasource-pool-druid-multiple</module>
|
||||
</modules>
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user