`

org.springframework.context.NoSuchMessageException:错误

阅读更多

Spring国际化资源文件问题,开发中遇到了,从网上找的(http://chinaliwee.blog.163.com/blog/static/34118206200873114211645/)自己备用学习。

 
用Spring做国际化时经常会报:
org.springframework.context.NoSuchMessageException: No message found under code 'userlogin' for locale 'zh_CN'.
at org.springframework.context.support.DelegatingMessageSource.getMessage(DelegatingMessageSource.java:65)
at org.springframework.context.support.AbstractApplicationContext.getMessage(AbstractApplicationContext.java:646)
at com.neusoft.Test.Test.main(Test.java:43)
Exception in thread "main"
这样的错误。
总结一下,有可能由以下原因造成:
1.如果你使用eclipse创建的工程是class和src分开的,那么资源属性文件一定要放在src目录以内。
2.属性文件名的写法:
messages_zh_CN.properties (中文)
messages_en_US.properties (英文)
3.配置messageSource这个bean(注意:一定是messageSource不是messageResource ,这是Spring规定的)
<bean >
<property >
<list>
<value>messages</value>
</list>
</property>
</bean>

 

<bean id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource">
<description>居然对Bean的命名有要求,只能命名成messageSource</description>
<property name="basenames">
<list>
<value>messages</value>
<value>mcCustomer</value>
<value>mcSys</value>
</list>
</property>
</bean>

 

----------------------------

我刚好就是这个问题,望大家小心!

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics