mirror of
https://github.com/Hello-hao/Tbed.git
synced 2024-04-21 12:32:10 +00:00
:art:修改系统配置表数据结构,添加数据库连接检测
This commit is contained in:
@@ -1,24 +1,23 @@
|
||||
package cn.hellohao;
|
||||
|
||||
import javax.servlet.MultipartConfigElement;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import cn.hellohao.utils.Print;
|
||||
import cn.hellohao.dao.KeysMapper;
|
||||
import cn.hellohao.utils.FirstRun;
|
||||
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.jdbc.DatabaseDriver;
|
||||
import org.springframework.boot.web.servlet.MultipartConfigFactory;
|
||||
import org.springframework.boot.web.servlet.ServletComponentScan;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
import org.springframework.jdbc.support.DatabaseStartupValidator;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
import org.springframework.util.unit.DataSize;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.Scanner;
|
||||
import javax.servlet.MultipartConfigElement;
|
||||
import javax.sql.DataSource;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@SpringBootApplication
|
||||
@Configuration
|
||||
@@ -30,6 +29,31 @@ public class TbedApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(TbedApplication.class, args);
|
||||
}
|
||||
|
||||
//延缓Spring Boot启动时间直到数据库启动的方法
|
||||
@Bean
|
||||
public DatabaseStartupValidator databaseStartupValidator(DataSource dataSource) {
|
||||
DatabaseStartupValidator databaseStartupValidator = new DatabaseStartupValidator();
|
||||
databaseStartupValidator.setDataSource(dataSource);
|
||||
databaseStartupValidator.setValidationQuery(DatabaseDriver.POSTGRESQL.getValidationQuery());
|
||||
return databaseStartupValidator;
|
||||
}
|
||||
@Bean
|
||||
public static BeanFactoryPostProcessor dependsOnPostProcessor() {
|
||||
return bf -> {
|
||||
// Let beans that need the database depend on the DatabaseStartupValidator
|
||||
// like the JPA EntityManagerFactory or Flyway
|
||||
String[] flyway = bf.getBeanNamesForType(FirstRun.class);
|
||||
Stream.of(flyway)
|
||||
.map(bf::getBeanDefinition)
|
||||
.forEach(it -> it.setDependsOn("databaseStartupValidator"));
|
||||
|
||||
String[] jpa = bf.getBeanNamesForType(KeysMapper.class);
|
||||
Stream.of(jpa)
|
||||
.map(bf::getBeanDefinition)
|
||||
.forEach(it -> it.setDependsOn("databaseStartupValidator"));
|
||||
};
|
||||
}
|
||||
/**
|
||||
* 文件上传配置
|
||||
* @return
|
||||
|
||||
Reference in New Issue
Block a user