spring - 正在加载资源包: Spring

标签 spring resourcebundle

我正在尝试在 Spring 中使用 ResourceBundleMessageSource。这是我的项目结构: enter image description here

这是 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 的子目录中来完成这项工作吗?

最佳答案

您需要在此处给出文件夹名称 -

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

关于spring - 正在加载资源包: Spring,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10929179/

相关文章:

java - 使用 Angular js、Spring、hibernate 一次保存大量行

java - spring data jpa中的store是什么?

ios - 缩放/捏合 UIWebView 中加载的 pdf

java - ResourceBundle 的变量查找参数?

java - 在服务器停止之前运行 Java 代码

java - 如何使用 "size"作为 hibernate/jpa 实体中的字段名称?

java - Spring 数据 Neo4j : Application exception overridden by rollback exception

JavaFX:在 FXML 中从 ResourceBundle 访问非字符串对象

jsp - JSTL 中的资源包显示问号?

spring - JSF - 来自 Spring bean 和数据库的资源包