35 lines
1.1 KiB
Java
35 lines
1.1 KiB
Java
package com.rnb;
|
|
|
|
import org.springframework.boot.SpringApplication;
|
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
|
|
import org.springframework.context.ConfigurableApplicationContext;
|
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
|
|
|
import javax.sql.DataSource;
|
|
|
|
/**
|
|
* 应用启动类
|
|
*
|
|
* @author Alex.Qu
|
|
* @since 0.0.1
|
|
*/
|
|
@SpringBootApplication
|
|
@ConfigurationPropertiesScan // 开启配置属性绑定
|
|
@EnableScheduling
|
|
public class RnBApplication {
|
|
public static void main(String[] args) {
|
|
ConfigurableApplicationContext ac = SpringApplication.run(RnBApplication.class, args);
|
|
try {
|
|
// ===== 在项目初始化bean后检验数据库连接是否
|
|
DataSource dataSource = (DataSource) ac.getBean("dataSource");
|
|
dataSource.getConnection().close();
|
|
} catch (Exception e) {
|
|
// e.printStackTrace();
|
|
System.out.println(e.getMessage());
|
|
// ===== 当检测数据库连接失败时, 停止项目启动
|
|
System.exit(-1);
|
|
}
|
|
}
|
|
}
|