以下配置是在配置springMVC的validator 的資源文件時的配置
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource"> <property name="basenames" value="messages"/> <!--指定文件的編碼--> <property name="fileEncodings" value="utf8"/> <!--對資源文件的緩存時間--> <property name="cacheSeconds" value="120"/> </bean>
但是卻出現了國際化錯誤。
查閱資料后,發現,當我們加載src下包里的文件時,應該使程序定位到classpath再加載文件。
解決方案:
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource"> <property name="basenames" value="classpath:messages"/> <!--指定文件的編碼--> <property name="fileEncodings" value="utf8"/> <!--對資源文件的緩存時間--> <property name="cacheSeconds" value="120"/> </bean>