mirror of
https://github.com/201206030/novel-plus.git
synced 2025-04-26 09:20:50 +00:00
perf: 连接池统一创建
This commit is contained in:
parent
82658f3b5f
commit
4b1507b2d1
@ -1,6 +1,5 @@
|
||||
package com.java2nb;
|
||||
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
@ -34,22 +33,15 @@ public class AdminApplication {
|
||||
@Bean
|
||||
public CommandLineRunner commandLineRunner(ApplicationContext ctx, DataSource dataSource) {
|
||||
return args -> {
|
||||
if (dataSource instanceof HikariDataSource) {
|
||||
// 如果使用的是HikariDataSource,需要提前创建连接池,而不是在第一次访问数据库时才创建,提高第一次登录的速度
|
||||
log.info("创建连接池...");
|
||||
try (Connection connection = dataSource.getConnection()) {
|
||||
HikariDataSource hikariDataSource = (HikariDataSource) dataSource;
|
||||
log.info("最小空闲连接数:{}", hikariDataSource.getMinimumIdle());
|
||||
log.info("最大连接数:{}", hikariDataSource.getMaximumPoolSize());
|
||||
log.info("创建连接池完成.");
|
||||
log.info("数据库:{}", connection.getMetaData().getDatabaseProductName());
|
||||
log.info("数据库版本:{}", connection.getMetaData().getDatabaseProductVersion());
|
||||
}
|
||||
log.info("创建连接池...");
|
||||
try (Connection connection = dataSource.getConnection()) {
|
||||
log.info("创建连接池完成.");
|
||||
log.info("数据库:{}", connection.getMetaData().getDatabaseProductName());
|
||||
log.info("数据库版本:{}", connection.getMetaData().getDatabaseProductVersion());
|
||||
}
|
||||
log.info("项目启动啦,访问路径:{}",
|
||||
"http://" + InetAddress.getLocalHost().getHostAddress() + ":" + ctx.getEnvironment()
|
||||
.getProperty("server.port"));
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user