perf: 提高第一次登录速度

This commit is contained in:
xiongxiaoyang 2025-03-19 00:09:10 +08:00
parent d9f9fd8bd2
commit 4b00ea68a9

View File

@ -11,6 +11,7 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.transaction.annotation.EnableTransactionManagement; import org.springframework.transaction.annotation.EnableTransactionManagement;
import javax.sql.DataSource;
import java.net.InetAddress; import java.net.InetAddress;
@ -23,14 +24,20 @@ import java.net.InetAddress;
@EnableCaching @EnableCaching
@Slf4j @Slf4j
public class AdminApplication { public class AdminApplication {
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(AdminApplication.class, args); SpringApplication.run(AdminApplication.class, args);
} }
@Bean @Bean
public CommandLineRunner commandLineRunner(ApplicationContext ctx) { public CommandLineRunner commandLineRunner(ApplicationContext ctx, DataSource dataSource) {
return args -> { return args -> {
log.info("项目启动啦,访问路径:{}", "http://" + InetAddress.getLocalHost().getHostAddress() + ":" + ctx.getEnvironment().getProperty("server.port")); // 提前创建连接池而不是在第一次访问数据库时才创建提高第一次登录速度
log.info("创建连接池...");
dataSource.getConnection();
log.info("项目启动啦,访问路径:{}",
"http://" + InetAddress.getLocalHost().getHostAddress() + ":" + ctx.getEnvironment()
.getProperty("server.port"));
}; };
} }