Internalization in Spring Boot Application

Tags: , ,

Sorry for my english. I am working on a spring boot application and I have the following situation. I implemented internalization and I created a following configuration class

public class WebMvcConfiguration implements WebMvcConfigurer {   

    public LocaleResolver localeResolver() {
        AcceptHeaderLocaleResolver localeResolver = new AcceptHeaderLocaleResolver();
        localeResolver.setDefaultLocale(new Locale("es_ES"));
        return localeResolver;
    public Validator getValidator() {
        LocalValidatorFactoryBean bean = new LocalValidatorFactoryBean();
        return bean;

    public MessageSource resourceBundleMessageSource() {
        ReloadableResourceBundleMessageSource messageSource
                = new ReloadableResourceBundleMessageSource();
        return messageSource;


Also I have two properties files and

And I defined a User entity class like this:

@Table(name = "users", uniqueConstraints = @UniqueConstraint(columnNames = "email"))
public class User implements Serializable {    

    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", table = "users", nullable = false)
    private Long id;

    @NotEmpty(message = "{not.field.empty}")
    @NotNull(message = "{not.field.empty}")
    @Column(name = "name")
    private String name;

    @Column(name = "lastname", table = "users", nullable = false, length = 100)
    private String lastname;

    @Column(name = "birthday", table = "users")
    @NotNull(message = "birthday {not.empty.field}")
    private Date birthday;


When I try to test validation by calling following endpoint

    public ResponseEntity<?> createUser(@Valid @RequestBody User user) {

If validation failes, I’m getting all error messages correctly.

    "timestamp": 1599168856694,
    "status": 400,
    "error": "Not validate field",
    "message": [
        "birthday Obligatory filed"
    "path": "/api/v1/users"

But when I use @Valid in a Service class like this

    public User saveUser(@Valid User user) { 

I don’t get the translated messages error messages.

    "timestamp": 1599169130869,
    "status": 400,
    "error": "Not validate field",
    "message": [
        "roles {not.empty.field}",
        "birthday {not.empty.field}"
    "path": "/api/v1/users"

Does anybody knows what’s the issue here? Thanks


Assuming your saveUser service method is getting called only from the REST API endpoint method “createUser” which is already validating the USER entity. I do not see any need for using @Valid in the service method argument as well. The rest endpoint is already doing the needful.

This post might help you –

Source: stackoverflow