我使用的是Spring 3,我在applicationContext.xml中有以下配置:
<bean id="validationMessageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource"
p:basename="classpath:messages/validation_messages" p:defaultEncoding="UTF-8" p:cacheSeconds="3" />
<bean id="globalValidator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean">
<property name="validationMessageSource">
<ref bean="validationMessageSource" />
</property>
</bean>
Run Code Online (Sandbox Code Playgroud)
一切都可以正常使用locales等.
但是,我想知道是否可以将语言环境注入我构建的自定义验证器.我已经创建了一个@CheckZip用于验证邮政编码的注释.但由于邮政编码在不同的国家/地区有不同的格式,我很好奇是否可以将当前的语言环境放入验证器中.