Simon Wong opened SPR-9708 and commented

Status Quo

WebMvcConfigurationSupport instantiates a LocalValidatorFactoryBean if JSR 303 is supported. However, it does not set the Spring MessageSource as the messageInterpolator by default.

Workaround

Extend WebMvcConfigurationSupport and add the following 2nd statement.

validator = (Validator) BeanUtils.instantiate(clazz);
((LocalValidatorFactoryBean) validator).setValidationMessageSource(messageSource); // messageSource is Autowired

Affects: 3.1 GA, 3.1.1, 3.1.2

Issue Links: - #16248 Add support for custom messages when using Apache BVAL as JSR303 validation provider

2 votes, 7 watchers

Comment From: spring-projects-issues

Juergen Hoeller commented

The problem here is that setValidationMessageSource relies on non-standard features in Hibernate Validator, even requiring Hibernate Validator 4.1 or higher there. As of Bean Validation 1.1 (coming next year as part of the EE 7 umbrella), we might get a standard variant for customizing message lookup which suggests that we can do it by default then. However, this will be considered within the Spring Framework 3.3 timeline, not within 3.2 anymore.

Juergen

Comment From: spring-projects-issues

Simon Wong commented

Could I know whether Spring 4 support the customized message lookup if Bean Validation 1.1 is in use?

Comment From: spring-projects-issues

Juergen Hoeller commented

Yes, it does - but just against Hibernate Validator 5, I'm afraid. Even as of Bean Validation 1.1, there is still no standard way to define a ResourceBundle for a MessageInterpolator, other than through Hibernate's custom ResourceBundleLocator mechanism...

Juergen