Home > Back-end >  How to change Spring Security error message language?
How to change Spring Security error message language?

Time:01-09

I use Spring Security for my server. There is a piece of code from my sign in controller, that returns error messages in German instead of English. How to fix it?

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

I know it is possible to solve the problem with localization but I am sure there must be an easier solution.

CodePudding user response:

Add this http header to your authorization request 'Accept-Language': 'en'

  • Related