55 lines
2.0 KiB
Java
55 lines
2.0 KiB
Java
|
|
package com.yj.earth;
|
||
|
|
|
||
|
|
import com.yj.earth.business.service.SourceService;
|
||
|
|
import com.yj.earth.common.config.ServerConfig;
|
||
|
|
import com.yj.earth.common.service.ServerInitService;
|
||
|
|
import com.yj.earth.common.util.SdkUtil;
|
||
|
|
import com.yj.earth.datasource.DatabaseManager;
|
||
|
|
import lombok.extern.slf4j.Slf4j;
|
||
|
|
import org.springframework.boot.CommandLineRunner;
|
||
|
|
import org.springframework.boot.SpringApplication;
|
||
|
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||
|
|
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||
|
|
import org.springframework.context.annotation.EnableAspectJAutoProxy;
|
||
|
|
|
||
|
|
import javax.annotation.Resource;
|
||
|
|
import java.io.IOException;
|
||
|
|
|
||
|
|
@Slf4j
|
||
|
|
@EnableAspectJAutoProxy
|
||
|
|
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
|
||
|
|
public class ServerApp implements CommandLineRunner {
|
||
|
|
@Resource
|
||
|
|
private SourceService sourceService;
|
||
|
|
@Resource
|
||
|
|
private ServerConfig serverConfig;
|
||
|
|
@Resource
|
||
|
|
private ServerInitService serverInitService;
|
||
|
|
|
||
|
|
public static void main(String[] args) throws IOException {
|
||
|
|
// 启动项目SDK服务
|
||
|
|
SdkUtil.startSdkIfConfigured();
|
||
|
|
// 初始化数据库相关操作
|
||
|
|
String activeDataSource = DatabaseManager.getActiveDataSource();
|
||
|
|
// 获取数据库类型
|
||
|
|
DatabaseManager.DatabaseType dbType = DatabaseManager.DatabaseType.valueOf(activeDataSource.toUpperCase());
|
||
|
|
// 初始化数据库
|
||
|
|
DatabaseManager.initDatabase(dbType);
|
||
|
|
// 启动应用服务
|
||
|
|
SpringApplication application = new SpringApplication(ServerApp.class);
|
||
|
|
// 允许循环引用
|
||
|
|
application.setAllowCircularReferences(true);
|
||
|
|
// 启动服务
|
||
|
|
application.run(args);
|
||
|
|
}
|
||
|
|
|
||
|
|
@Override
|
||
|
|
public void run(String... args) throws Exception {
|
||
|
|
// 初始化资源
|
||
|
|
serverInitService.init();
|
||
|
|
// 检查默认数据
|
||
|
|
serverInitService.checkDefaultData();
|
||
|
|
log.info("项目文档地址: {}", "http://" + serverConfig.getHost() + ":" + serverConfig.getPort() + "/doc.html");
|
||
|
|
}
|
||
|
|
}
|