【问题标题】:Can you change the 401 error response?你能改变401错误响应吗?
【发布时间】:2016-12-18 22:51:06
【问题描述】:

我的问题是,你能改变 401 错误信息的响应结构吗?

{
    "error": "unauthorized",
    "error_description": "No AuthenticationProvider found for org.springframework.security.authentication.UsernamePasswordAuthenticationToken"
}

例如

{
    "timestamp" : 123124354,
    "status" : 401,
    "message" : "The username or password are not valid!"
}

【问题讨论】:

    标签: spring spring-security spring-boot


    【解决方案1】:

    这是不久前回答的:Modify default JSON error response from Spring Boot Rest Controller。检查reference guide 我建议使用@ControllerAdvice,以便在定义 JSON 响应的返回方式方面为您提供最大的灵活性。

    【讨论】:

      猜你喜欢
      • 2016-10-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-03
      • 1970-01-01
      • 2022-11-10
      • 2013-08-04
      • 2023-03-19
      相关资源
      最近更新 更多