验证按预期工作,但消息仅以英文显示。我用自己的消息发日语。
问题是我收到了乱码的日语验证消息。我正在使用带有hibernate-validator-4.2.0.Final.jar的validation-api-1.0.0.GA.jar。我有ValidationMessages.properties和ValidationMessages_ja.properties。文件是utf8:例如: firstName=姓をご記入ください。出炉:§²ãéAgeãããã
我在上面的bean中使用了一个要验证的属性:@Size(min = 1,message = "{myErrorMsg}")私有字符串myAttribute;
在我的spring.xml中:
<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<!-- <property name="basename" value="classpath:tc-messages" /> -->
<property name="basenames">
<list>
<value>classpath:tc-messages</value>
<value>classpath:ValidationMessages</value>
</list>
</property>
<property name="defaultEncoding" value="UTF-8" />
</bean>
和:
<bean id="localeResolver"
class="org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver">
<!-- <property name="defaultLocale" value="en_us" /> -->
</bean>
我遗漏了什么吗?
谢谢你,罗德
发布于 2012-04-27 23:37:38
我想说编码可能在构建时丢失了。你使用的构建工具知道你的文件编码吗?例如,对于Maven,您需要以下属性:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
https://stackoverflow.com/questions/10352755
复制相似问题