`

NoSuchMessageException的异常

    博客分类:
  • bug
阅读更多
现象:No message found under code 'userLogin' for locale 'en_US'
原因:
    这个异常的根本原因是context找不到properties文件的位置
我们通常使用eclipse,默认设置src到类路径(你可以通过导航器查看.classpath文件)
因此context只会从这些类路径去找,而在项目名称下是找不到的
所以只要把properties文件放在src下面,就可以正常输出了

    如果你必须把properties文件放在某个包下,那么就必须给message文件配置好路径。如果你的message(message_en_US.properties、message_zh_CN.properties)在com.company.information包下,则applicationContext.xml文件应这样配置:
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
       <property name="basenames">
         <list>
            <value>com.company.information.message</value>
         </list>
       </property>
</bean>

    注意:com.company.information.message的message如果你的properties文件名是messages_~.properties、messages_~.properties那么,这个配置中的message就应改写成为messages。
    这个问题其实是资源文件的命名问题,资源文件有3种命名方式:
baseName_language_country.properties.
baseName_language.properties.
baseName.properties.
其中baseName是资源文件的基本名,用户可以自由定义,但该基本名要与配置文件相一致。而language和country都不可随意变化,必须是java所支持的语言和国家。
分享到:
评论
1 楼 bcw104 2009-04-29  
还是没解决,页面我在页面上都可以调用属性文件里面东西,在后台就调不了.

相关推荐

Global site tag (gtag.js) - Google Analytics