我正在尝试在Spring中使用ResourceBundleMessageSource。这是我的项目结构:
这是xml配置:
<bean name="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename">
<value>messages</value>
</property>
</bean>
当我尝试加载应用程序上下文时,我遇到以下异常:
Jun 7, 2012 2:44:00 PM org.springframework.context.support.ResourceBundleMessageSource getResourceBundle
WARNING: ResourceBundle [messages] not found for MessageSource: Can't find bundle for base name messages, locale en_US
Exception in thread "main" org.springframework.context.NoSuchMessageException: No message found under code 'user.welcome' for locale 'en_US'.
at org.springframework.context.support.AbstractMessageSource.getMessage(AbstractMessageSource.java:135)
at org.springframework.context.support.AbstractApplicationContext.getMessage(AbstractApplicationContext.java:1192)
at com.pramati.core.MessageResolver.getMessage(MessageResolver.java:19)
如果我将资源包文件直接放在资源文件夹下,我没有收到此错误。它工作正常。有人可以通过将资源包放在src / main / resources的子目录中让我知道如何才能完成这项工作?
答案 0 :(得分:5)
你需要在这里给出文件夹名称 -
<property name="basename">
<value>resourceBundles/messages</value>
</property>