Spring @PreDestroy: No logging because Logback stops too soon

后端 未结 2 662
悲&欢浪女
悲&欢浪女 2021-02-07 14:29

In my project, I am using Logback as logging facility. I have the following class

@Component
class Test {
    @PreDestroy
    public void destroy() {
        try         


        
2条回答
  •  别跟我提以往
    2021-02-07 14:45

    To pick up Dovmo's answer. It's all about ordering. I have the same issue on Tomcat 8.5.x. Bacially, the initializer does an addListener, you don't have any control over the listener. At shutdown, Tomcat reverse-iterates that list, picking the Logback listener first: Spring won't log anything.

    A custom listener won't help because you cannot prepend it. What works for me on Tomcat is:

    
        ch.qos.logback.classic.servlet.LogbackServletContextListener
    
    
        org.springframework.web.context.ContextLoaderListener
    
    
    
        logbackDisableServletContainerInitializer
        true
    
    

提交回复
热议问题