【问题标题】:How to disable some warnings in Spring Boot如何在 Spring Boot 中禁用某些警告
【发布时间】:2020-09-30 00:11:04
【问题描述】:

在我的应用程序中,我可以上传文件(最大大小为 10MB)。我为太大的文件创建了一个异常处理程序,但控制台仍然显示警告说有人尝试上传太大的文件:

2020-09-30 01:38:59.306  WARN 2476 --- [nio-8080-exec-3] .m.m.a.ExceptionHandlerExceptionResolver : Resolved [org.springframework.web.multipart.MaxUploadSizeExceededException: Maximum upload size exceeded; nested exception is java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.impl.SizeLimitExceededException: the request was rejected because its size (26937892) exceeds the configured maximum (10485760)]

异常处理程序:

    @ExceptionHandler(MaxUploadSizeExceededException.class)
    public void oversizedFilesHandler(MaxUploadSizeExceededException e){
        accountService.writeExceptionToFile(e);
    }

是否可以禁用这些警告?

【问题讨论】:

    标签: java spring-boot exception file-upload


    【解决方案1】:

    您可以通过将日志级别添加到属性文件来实现:

    规则: logging.level.xxxx=LEVEL

    地点:

    • LEVELTRACE、DEBUG、INFO、WARN、ERROR、FATAL、OFF 之一。

    • xxxx 是一个包/类。

    我们将规则应用于您的案例:

    logging.level.org.springframework.web=ERROR 
    

    甚至更薄:

    logging.level.org.springframework.web.multipart =ERROR 
    

    因此,只有 ERROR、FATAL 和 OFF 级别将记录到您的控制台。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-09
      • 2017-10-12
      • 2016-07-21
      • 1970-01-01
      • 2022-01-08
      • 2013-10-19
      • 2019-07-03
      • 2015-02-14
      相关资源
      最近更新 更多