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