我的问题是,您是否可以更改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!"
}
答案 0 :(得分:1)
前一段时间回答:Modify default JSON error response from Spring Boot Rest Controller。检查reference guide我建议使用@ControllerAdvice
,以便最灵活地定义如何返回JSON响应。