【问题标题】:How to change Spring Security error message language?如何更改 Spring Security 错误消息语言?
【发布时间】:2023-01-09 01:08:31
【问题描述】:

我的服务器使用 Spring Security。我的登录控制器中有一段代码,它以德语而不是英语返回错误消息。如何解决?

try{
    authentication = authenticationManager.authenticate(
        new UsernamePasswordAuthenticationToken(user.getUsername(), user.getPassword())
    );
}catch(AuthenticationException e){
    response.setErrorMessage(e.getMessage());
    return ResponseEntity.status(401).body(response);
}

我知道可以通过本地化解决问题,但我相信一定有更简单的解决方案。

【问题讨论】:

    标签: java spring spring-security localization


    【解决方案1】:

    将此 http 标头添加到您的授权请求 '接受语言':'en'

    【讨论】:

    • 谢谢,成功了!
    猜你喜欢
    • 1970-01-01
    • 2022-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多