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"
这样的错误。
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>
<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>
----------------------------
我刚好就是这个问题,望大家小心!
相关推荐
java解决org.springframework.web.context.ContextLoaderListener
org.springframework.context.support-3.0.4.RELEASE.jar org.springframework.context-3.0.4.RELEASE.jar org.springframework.core-3.0.4.RELEASE.jar org.springframework.expression-3.0.4.RELEASE.jar org....
org.springframework.spring-context-2.5.6
org.springframework.web.context.support.ServletContextPropertyPlaceholderConfigurer.class org.springframework.web.context.support.ServletContextResource.class org.springframework.web.context.support....
org.springframework.flex-1.0.3.RELEASE.jar.zip用于JAR包,org.springframework.flex-1.0.3.RELEASE.jar.zip用于JAR包org.springframework.flex-1.0.3.RELEASE.jar.zip用于JAR包org.springframework.flex-1.0.3....
org.springframework.web.jar
org.springframework.context.support-3.1.0.M1.jar包,无毒下载
org.springframework.context-3.1.1.RELEASE.jar java 开发专用
org.springframework.context_3.0.5.release.jar.zip
import org.springframework.web.socket.server.standard.ServerEndpointExporter;
org.springframework.mock.jndi.ExpectedLookupTemplate.class org.springframework.mock.jndi.SimpleNamingContext.class org.springframework.mock.jndi.SimpleNamingContextBuilder.class org.springframework....
org.springframework.context.support-3.1.RELEASE.jar org.springframework.context-3.1.RELEASE.jar org.springframework.core-3.1.RELEASE.jar org.springframework.expression-3.1.RELEASE.jar org.spring...
Error creating bean with name 'org.springframework.web.servlet.handler.SimpleUrlHandlerMapping#0' defined in ServletContext resource [/WEB-INF/springMVC-servlet.xml]: Initialization of bean failed;...
org.springframework.context-3.0.7.RELEASE.jar
aopalliance-1.0.jar,org.springframework.aop-3.0.0.RELEASE.jar,org.springframework.jdbc-3.0.0.RELEASEorg.springframework.beans-3.0.0.RELEASE.jar等
org.springframework.core.jar
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.interceptor.TransactionInterceptor#0': Error setting property values; nested ...
org.springframework.asm-3.0.5.RELEASE.jar
org.springframework.web.struts-3.1.0.M2.jar