这听起来像将您对日志记录配置的自定义推迟到
LoggingApplicationListener运行之后才起作用。
LoggingApplicationListener响应
ApplicationEnvironmentPreparedEvent并执行的顺序执行初始化
Ordered.HIGHEST_PRECEDENCE+11。为了防止您的自定义配置被覆盖,您可以将您的自定义逻辑封装在
SmartApplicationListener响应相同事件但顺序较低的中,使其在
LoggingApplicationListener以下时间运行:
public class CustomLoggingConfigurationApplicationListener implements SmartApplicationListener { @Override public void onApplicationEvent(ApplicationEvent event) { // Customise the logging configuration } @Override public int getOrder() { return Ordered.HIGHEST_PRECEDENCE + 12; } @Override public boolean supportsEventType(Class<? extends ApplicationEvent> eventType) { return ApplicationEnvironmentPreparedEvent.class.isAssignableFrom(eventType); } @Override public boolean supportsSourceType(Class<?> sourceType) { return true; }}
您可以创建侦听器并将其注册到应用程序的main方法中:
@SpringBootApplicationpublic class Application { public static void main(String[] args) { new SpringApplicationBuilder(Application.class) .listeners(new CustomLoggingConfigurationApplicationListener()) .run(args); }}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)