Pregunta

I am using spring-data-rest and I need to configure messages.properties using annotations, What I have done in my configuration class is,

@Bean public ReloadableResourceBundleMessageSource messageSource(){
    ReloadableResourceBundleMessageSource reloadableResourceBundleMessageSource = new ReloadableResourceBundleMessageSource();
    reloadableResourceBundleMessageSource.setBasename("messages");
    return reloadableResourceBundleMessageSource;
}

and tries to access the property in my messages.property file,

notnull.empty=rr is required.

as,

ValidationUtils.rejectIfEmptyOrWhitespace(arg1, "rr", "notnull.empty", "test is required.");

in my Validation Class. But the default message only received and if I remove default message null is received. Is it possible to configure validation messages property file through annotation? Am new to springs, so I cant bet it. Thanks in advance.

¿Fue útil?

Solución

The problem is that it is not able to find the message file. It is needed to provide the correct location path to the setBasename method. You can do it in several ways, I will show you two:

1.Using a path from the project root like:

    reloadableResourceBundleMessageSource.setBasename("/WEB-INF/messages/messages")‌​;

2.Using a path within the classpath, like:

    reloadableResourceBundleMessageSource.setBasename("classpath:/messages/messages")‌​;

I prefer the first because servers use to cache files loaded from the classpath and it makes more difficult to catch changes in the message files.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top