Spring 国际化 异常:No message found under code 'message' for locale 'zh_CN'.


 

以下配置是在配置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>

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM