java - 找不到 MessageSource Spring MVC

标签 java spring

我正在尝试验证表单并从属性文件加载消息“ErrorMessages.properties”。属性文件的位置如图所示

Project Structure

我的调度程序 servlet 中有以下代码

<!-- Register the properties files -->
    <bean id="messageSource"
          class="org.springframework.context.support.ResourceBundleMessageSource">
        <property name="basename" value="classpath:ErrorMessages.properties" />
        <property name="useCodeAsDefaultMessage" value="true" />
    </bean>

项目已部署,但我看不到错误消息。我收到以下警告

WARNING: ResourceBundle [classpath:ErrorMessages.properties] not found for MessageSource: Can't find bundle for base name classpath:ErrorMessages.properties, locale en_GB

是的,我确实有另一个属性加载器

<context:property-placeholder location="classpath:conf.properties" />

我是 Spring 新手,我尝试解决这个问题已经有一段时间了。

最佳答案

您应该将 bundle 放在标准位置:

 src/main/resources 

如果您遵循此约定,您的 messageSource bean 应如下定义:

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

message_en_GB.propertiesspring.xml 放在同一文件夹中。

关于java - 找不到 MessageSource Spring MVC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22759594/

相关文章:

java - 关于 ESAPI 日志事件

java - 解析日期并在 Java 中遇到 'static reference to the non-static method' 错误

java - Spring MessageSource 是否支持多类路径?

css - Spring-Boot ResourceLocations 未添加导致 404 的 css 文件

java - 执行 jar 文件时没有显示 jasper 报告

java - 如何修复 Java JNI DLL 依赖项

Java XMLReader 不清除多字节 UTF-8 编码属性

java - Spring Batch + Spring API REST

java - 调试 JAXB/JBOSS 行为所需的建议

java - 将属性编辑器应用于模型中的对象