Loading resource bundles: Spring

寵の児 提交于 2019-12-21 21:33:07

问题


I am trying to use ResourceBundleMessageSource in Spring. Here is my project structure:

And here is the xml configuration:

<bean name="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
    <property name="basename">
        <value>messages</value>
    </property>
</bean>

When I try to load the application context, I am getting the following exception:

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)

If I put my resource bundles file directly under resources folder, I am not getting this error. It is working fine. Can someone let me know how could I get this work by putting resource bundles in a subdirectory of src/main/resources?


回答1:


you need to give folder name here -

<property name="basename">
      <value>resourceBundles/messages</value>
</property>


来源:https://stackoverflow.com/questions/10929179/loading-resource-bundles-spring

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!