I am working on Spring Boot, I have used Hibernate Validator to validate my beans. I have added a custom key with the @NotEmpty
annotation, and add thos key/value pair in message.properties, but it's not getting its value from message.property
Here is my bean with validation annotation:
public class CategoryBean {
@NotEmpty(message = "{category.name.notempty}")
private String name;
----getter setter-----
}
message.properties (path:src/main/resources/message.properties)
category.name.notempty=Sorry! Category can't be empty
I have also configured message resource
@Bean
public MessageSource messageSource() {
ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
messageSource.setBasename("message");
return messageSource;
}
I also configured LocalValidatorFactoryBean
@Bean
public LocalValidatorFactoryBean validator() {
final LocalValidatorFactoryBean localValidatorFactoryBean = new LocalValidatorFactoryBean();
localValidatorFactoryBean.setValidationMessageSource(messageSource());
return localValidatorFactoryBean;
}
Whenever I am validating this bean, it's showing its key instead of its value.
Hibernate validator default search message key inside ValidationMessages.properties
so whenever I am adding ValidationMessages.properties
file add there message this key value then it's working fine for me.
But I don't want to add ValidationMessage.properties file, instead of this I want to handle this message key in my message.properties file.
I know there are already some question related this in stack overflow, but those solutions are not solving my problem. I am unable to find out what I am doing wrong here.