Spring boot embedded tomcat logs

后端 未结 7 1674
南笙
南笙 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:

      <dependency>
          <groupId>org.slf4j</groupId>
          <artifactId>jul-to-slf4j</artifactId>
          <version>${slf4j.version}</version>
      </dependency>
      
    • 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)));
         }
      }
      
    0 讨论(0)
提交回复
热议问题