如何更改Spring Security错误消息语言?



我的服务器使用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);
}

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

添加此HTTP头到您的授权请求:'Accept-Language': 'en'

最新更新