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