Spring boot embedded tomcat logs

后端 未结 7 1695
南笙
南笙 2020-12-09 10:19

i\'m using spring boot embedded tomcat with spring boot 1.5.9 , im also using Log4j2.

recently i exerience problems during load, so i want to understand better the

7条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-09 10:49

    For slf4j and Spring Boot 2 hide exceptions from Tomcat and handle them by yourself:

    • Add to pom:

      
          org.slf4j
          jul-to-slf4j
          ${slf4j.version}
      
      
    • Add to config:

      @PostConstruct
      void postConstruct() {
          SLF4JBridgeHandler.install();
      }
      
    • Add to application.yaml

      logging:
          level:
            org.apache.catalina: off
      
    • Handle exception in ErrorController

      @Controller
      @Slf4j
      public class ErrorController implements 
                    org.springframework.boot.web.servlet.error.ErrorController {
          private static final String ERROR_PATH = "/error";
      
         @Autowired
         private ErrorAttributes errorAttributes;
      
         @Override
         public String getErrorPath() {
            return ERROR_PATH;
         }
      
         @RequestMapping(ERROR_PATH)
         public ModelAndView error(HttpServletRequest request) {
             return processException(errorAttributes.getError(new ServletWebRequest(request)));
         }
      }
      

提交回复
热议问题