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.transaction.annotation.EnableTransactionManagement;
import javax.sql.DataSource;
import java.net.InetAddress;
@ -18,19 +19,25 @@ import java.net.InetAddress;
@ServletComponentScan
@MapperScan("com.java2nb.*.dao")
@SpringBootApplication(exclude = {
org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration.class
org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration.class
})
@EnableCaching
@Slf4j
public class AdminApplication {
public static void main(String[] args) {
SpringApplication.run(AdminApplication.class, args);
}
@Bean
public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
public CommandLineRunner commandLineRunner(ApplicationContext ctx, DataSource dataSource) {
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"));
};
}