mirror of
https://github.com/LamGC/Oracle-Sentry.git
synced 2025-04-29 22:27:34 +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.springframework.beans.factory.annotation.Autowired;
|
||||
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.Configuration;
|
||||
import org.springframework.lang.NonNull;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author LamGC
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Configuration
|
||||
public class ApplicationInitiation implements ApplicationContextInitializer {
|
||||
public class ApplicationInitiation {
|
||||
|
||||
private final static Logger log = LoggerFactory.getLogger(ApplicationInitiation.class);
|
||||
|
||||
@ -99,20 +97,10 @@ public class ApplicationInitiation implements ApplicationContextInitializer {
|
||||
return manager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(ConfigurableApplicationContext applicationContext) {
|
||||
try {
|
||||
boolean result = initialDirectory();
|
||||
if (result) {
|
||||
System.exit(1);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean initialDirectory() throws IOException {
|
||||
@PostConstruct
|
||||
private void initialEnvironment() throws IOException {
|
||||
String[] directors = new String[] {
|
||||
"./config",
|
||||
identityDirectory,
|
||||
scriptsLocation
|
||||
};
|
||||
@ -121,23 +109,25 @@ public class ApplicationInitiation implements ApplicationContextInitializer {
|
||||
sshIdentityPath
|
||||
};
|
||||
|
||||
boolean hasFailure = false;
|
||||
for (String directory : directors) {
|
||||
File dir = new File(directory);
|
||||
if (!dir.exists() && !dir.mkdirs()) {
|
||||
if (!dir.exists()) {
|
||||
if (!dir.mkdirs()) {
|
||||
log.error("文件夹 {} 创建失败.", dir.getCanonicalPath());
|
||||
hasFailure = true;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (String file : files) {
|
||||
File dir = new File(file);
|
||||
if (!dir.exists() && !dir.createNewFile()) {
|
||||
if (!dir.exists()) {
|
||||
if (!dir.createNewFile()) {
|
||||
log.error("文件 {} 创建失败.", dir.getCanonicalPath());
|
||||
hasFailure = true;
|
||||
|
||||
}
|
||||
}
|
||||
log.info("目录检查完成.");
|
||||
return hasFailure;
|
||||
}
|
||||
log.debug("目录检查完成.");
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user