【问题标题】:Error response body is empty in Spring Boot 2.6Spring Boot 2.6 中的错误响应正文为空
【发布时间】:2022-01-13 04:01:12
【问题描述】:

Spring Web 堆栈上有一个应用程序。升级到最新的Spring Boot 2.6.1 后,我遇到了一个不寻常的问题。

以下代码

@RestController
@RequestMapping("sample")
class SampleController {
    @PostMapping
    fun doSomething(@RequestBody body: Any): Any {
        error("Error!")
    }
}

用于在早期版本中产生以下错误

{
    "timestamp": "2020-05-27T13:44:58.032+00:00",
    "status": 500,
    "error": "Internal Server Error",
    "message": "Error!",
    "path": "/sample"
}

但是升级后整个响应体都是空的。不是可以使用server.error.inclide-message: always 标志设置修复的message 字段,而是整个主体。 include-binding-errors: always 标志也无效。

我在 Spring Boot 更改日志中没有发现有关该行为的注释

【问题讨论】:

    标签: spring spring-boot kotlin spring-mvc


    【解决方案1】:

    所以这是 2.6.0 和 2.6.1 版本中的一个错误。在 2.6.2 中修复

    【讨论】:

    • 我使用的是 2.6.3,但仍然面临这个空响应问题。
    【解决方案2】:

    看看这个问题:https://github.com/spring-projects/spring-boot/issues/28953

    如果您允许访问 SecurityConfig 中的 /error whitelabel 页面,它应该会再次工作。但是,这似乎是一种解决方法,因为问题仍在处理中。

    【讨论】:

    • 好吧,/error 路径已经被安全机制忽略了。谢谢你提到这个问题。似乎 Web 和安全团队之间存在一些误解,因此问题没有简单的解决方案。也为 Pivotal 提供如此糟糕的生产解决方案感到羞耻。
    猜你喜欢
    • 2021-10-04
    • 2020-08-26
    • 1970-01-01
    • 2020-06-04
    • 2019-07-17
    • 1970-01-01
    • 2014-12-07
    • 1970-01-01
    • 2015-11-09
    相关资源
    最近更新 更多