从hibernate-validation覆盖默认的ValidationMessages.properties

时间:2014-01-16 17:42:55

标签: spring bean-validation hibernate-validator spring-validator

我正在尝试从Spring MVC应用程序中的默认hibernate-validation(5.0.2版本)覆盖ValidationMessages.properties。

但它继续使用jar中的内部ValidationMessages.properties。

更新:当我将* .properties文件复制到org \ hibernate \ validator时,它可以工作(但应该是另一种方式)...

这是我的配置:

@Configuration
@EnableWebMvc
@ComponentScan(basePackages = {"com.blueliv.search.*"} )
public class WebConfig extends WebMvcConfigurerAdapter {

  static Logger log =LoggerFactory.getLogger(WebMvcConfigurerAdapter.class);

  @Override
  public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
      converters.add(new GsonHttpMessageConverter());

      //converters.add(new MappingJackson2HttpMessageConverter());
  }

  @Bean
  public MethodValidationPostProcessor methodValidationPostProcessor() {
      return new MethodValidationPostProcessor();
  }

  @Bean
  public ExceptionHandlerExceptionResolver exceptionResolver() {
      return new ExceptionHandlerExceptionResolver();
  }

  @Bean
  public LocalValidatorFactoryBean validator() {
      LocalValidatorFactoryBean validatorFactoryBean = new LocalValidatorFactoryBean();
      validatorFactoryBean.setValidationMessageSource(getBundle());
      return validatorFactoryBean;
  }


  public ReloadableResourceBundleMessageSource getBundle(){
      log.debug("get bundle!");
      ReloadableResourceBundleMessageSource bundle = new ReloadableResourceBundleMessageSource();
      bundle.setBasenames("classpath:/i18n/validation/ValidatonMessages");
      return bundle;
  }


  @Override
  public Validator getValidator() {
      return validator();
  }

0 个答案:

没有答案