|
|
@@ -1,24 +1,16 @@
|
|
|
package cn.reghao.tnb.file.app.config;
|
|
|
|
|
|
-import cn.reghao.jutil.jdk.machine.id.MachineId;
|
|
|
-import cn.reghao.jutil.jdk.machine.id.MachineIdLinux;
|
|
|
-import cn.reghao.tnb.common.prop.LogProperties;
|
|
|
import cn.reghao.tnb.file.app.service.AliyunOss;
|
|
|
import cn.reghao.tnb.file.app.service.AliyunService;
|
|
|
import cn.reghao.tnb.file.app.db.mapper.StoreConfigMapper;
|
|
|
import cn.reghao.tnb.file.app.model.constant.OssType;
|
|
|
import cn.reghao.tnb.file.app.model.po.StoreConfig;
|
|
|
-import cn.reghao.tnb.log.Appenders;
|
|
|
-import cn.reghao.tnb.log.LoggerConfig;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.DisposableBean;
|
|
|
import org.springframework.boot.ApplicationArguments;
|
|
|
import org.springframework.boot.ApplicationRunner;
|
|
|
-import org.springframework.core.env.Environment;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
-import java.util.List;
|
|
|
-
|
|
|
/**
|
|
|
* @author reghao
|
|
|
* @date 2022-03-23 09:22:01
|
|
|
@@ -26,21 +18,15 @@ import java.util.List;
|
|
|
@Slf4j
|
|
|
@Component
|
|
|
public class SpringLifecycle implements ApplicationRunner, DisposableBean {
|
|
|
- private final Environment env;
|
|
|
- private final MachineId machineId;
|
|
|
- private final LogProperties logProperties;
|
|
|
private final AppProperties appProperties;
|
|
|
private final StoreConfigMapper storeConfigMapper;
|
|
|
private final OssConsoleClientFactory ossConsoleClientFactory;
|
|
|
private final AliyunOss aliyunOss;
|
|
|
private final AliyunService aliyunService;
|
|
|
|
|
|
- public SpringLifecycle(Environment env, LogProperties logProperties, AppProperties appProperties,
|
|
|
- StoreConfigMapper storeConfigMapper, OssConsoleClientFactory ossConsoleClientFactory,
|
|
|
- AliyunOss aliyunOss, AliyunService aliyunService) {
|
|
|
- this.env = env;
|
|
|
- this.machineId = new MachineIdLinux();
|
|
|
- this.logProperties = logProperties;
|
|
|
+ public SpringLifecycle(AppProperties appProperties, StoreConfigMapper storeConfigMapper,
|
|
|
+ OssConsoleClientFactory ossConsoleClientFactory, AliyunOss aliyunOss,
|
|
|
+ AliyunService aliyunService) {
|
|
|
this.appProperties = appProperties;
|
|
|
this.storeConfigMapper = storeConfigMapper;
|
|
|
this.ossConsoleClientFactory = ossConsoleClientFactory;
|
|
|
@@ -50,10 +36,6 @@ public class SpringLifecycle implements ApplicationRunner, DisposableBean {
|
|
|
|
|
|
@Override
|
|
|
public void run(ApplicationArguments args) throws Exception {
|
|
|
- if (logProperties.getEnabled()) {
|
|
|
- initLogConfig();
|
|
|
- }
|
|
|
-
|
|
|
int ossType = appProperties.getOssType();
|
|
|
StoreConfig storeConfig = storeConfigMapper.findByOssType(ossType);
|
|
|
if (ossType == OssType.localOss.getCode()) {
|
|
|
@@ -65,20 +47,11 @@ public class SpringLifecycle implements ApplicationRunner, DisposableBean {
|
|
|
aliyunOss.init(storeConfig1);
|
|
|
aliyunService.init(aliyunOss, storeConfig);
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- private void initLogConfig() {
|
|
|
- String wsUrl = logProperties.getWsUrl();
|
|
|
- if (wsUrl != null) {
|
|
|
- String token = logProperties.getToken();
|
|
|
- String app = env.getProperty("spring.application.name");
|
|
|
- String host = machineId.ipv4();
|
|
|
- String url = String.format("%s?token=%s&app=%s&host=%s", wsUrl, token, app, host);
|
|
|
- LoggerConfig.initLogger(List.of(Appenders.wsAppender(url, app, host)));
|
|
|
- }
|
|
|
+ log.info("FileService 启动...");
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void destroy() {
|
|
|
+ log.info("FileService 停止...");
|
|
|
}
|
|
|
}
|