mirror of
https://github.com/LamGC/Oracle-Sentry.git
synced 2025-04-30 06:37:42 +00:00
refactor: 调整运行环境的初始化时机.
调整初始化时机在所有 Bean 构造之前, 以更快的将缺失目录创建.
This commit is contained in:
parent
d81d07bd65
commit
6ed419b425
@ -9,21 +9,19 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.context.ApplicationContextInitializer;
|
|
||||||
import org.springframework.context.ConfigurableApplicationContext;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.lang.NonNull;
|
import org.springframework.lang.NonNull;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author LamGC
|
* @author LamGC
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("rawtypes")
|
|
||||||
@Configuration
|
@Configuration
|
||||||
public class ApplicationInitiation implements ApplicationContextInitializer {
|
public class ApplicationInitiation {
|
||||||
|
|
||||||
private final static Logger log = LoggerFactory.getLogger(ApplicationInitiation.class);
|
private final static Logger log = LoggerFactory.getLogger(ApplicationInitiation.class);
|
||||||
|
|
||||||
@ -99,20 +97,10 @@ public class ApplicationInitiation implements ApplicationContextInitializer {
|
|||||||
return manager;
|
return manager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@PostConstruct
|
||||||
public void initialize(ConfigurableApplicationContext applicationContext) {
|
private void initialEnvironment() throws IOException {
|
||||||
try {
|
|
||||||
boolean result = initialDirectory();
|
|
||||||
if (result) {
|
|
||||||
System.exit(1);
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean initialDirectory() throws IOException {
|
|
||||||
String[] directors = new String[] {
|
String[] directors = new String[] {
|
||||||
|
"./config",
|
||||||
identityDirectory,
|
identityDirectory,
|
||||||
scriptsLocation
|
scriptsLocation
|
||||||
};
|
};
|
||||||
@ -121,23 +109,25 @@ public class ApplicationInitiation implements ApplicationContextInitializer {
|
|||||||
sshIdentityPath
|
sshIdentityPath
|
||||||
};
|
};
|
||||||
|
|
||||||
boolean hasFailure = false;
|
|
||||||
for (String directory : directors) {
|
for (String directory : directors) {
|
||||||
File dir = new File(directory);
|
File dir = new File(directory);
|
||||||
if (!dir.exists() && !dir.mkdirs()) {
|
if (!dir.exists()) {
|
||||||
log.error("文件夹 {} 创建失败.", dir.getCanonicalPath());
|
if (!dir.mkdirs()) {
|
||||||
hasFailure = true;
|
log.error("文件夹 {} 创建失败.", dir.getCanonicalPath());
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (String file : files) {
|
for (String file : files) {
|
||||||
File dir = new File(file);
|
File dir = new File(file);
|
||||||
if (!dir.exists() && !dir.createNewFile()) {
|
if (!dir.exists()) {
|
||||||
log.error("文件 {} 创建失败.", dir.getCanonicalPath());
|
if (!dir.createNewFile()) {
|
||||||
hasFailure = true;
|
log.error("文件 {} 创建失败.", dir.getCanonicalPath());
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.info("目录检查完成.");
|
log.debug("目录检查完成.");
|
||||||
return hasFailure;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user