在一个普通的Java应用程序中,我发现this code重新加载了logback配置:
public void reload() {
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
ContextInitializer ci = new ContextInitializer(loggerContext);
URL url = ci.findURLOfDefaultConfigurationFile(true);
try {
JoranConfigurator configurator = new JoranConfigurator();
configurator.setContext(loggerContext);
loggerContext.reset();;
configurator.doConfigure(url);
} catch (JoranException je) {
// StatusPrinter will handle this
}
StatusPrinter.printInCaseOfErrorsOrWarnings(loggerContext);
}
但是在Spring Boot应用程序中,此代码无效,ci.findURLOfDefaultConfigurationFile(true)
将返回null
。
那么我该如何在Spring Boot应用程序中重新加载logback配置?