【问题标题】:Spring does not find messages.propertiesSpring没有找到messages.properties
【发布时间】:2017-07-16 11:14:15
【问题描述】:

我正在使用 Spring 框架开发一个 maven 项目。

我更喜欢使用 <spring:message .../> 标记并将我的消息注册到 .properties 文件中,而不是在 JSP 中编写原始文本。

我在请求页面时收到此警告:

找不到 MessageSource 的 ResourceBundle [messages]:不能 查找基本名称消息的捆绑包,区域设置 fr

这会带来关于未找到消息的异常(显然)。

这是我项目的层次结构:

my project's hierarchy

这是我的 springapp-servlet.xml :

<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:mvc="http://www.springframework.org/schema/mvc"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:aop="http://www.springframework.org/schema/aop"
   xmlns:context="http://www.springframework.org/schema/context"
   xsi:schemaLocation="http://www.springframework.org/schema/beans
                       http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
                       http://www.springframework.org/schema/mvc
                       http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
                       http://www.springframework.org/schema/aop
                       http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
                       http://www.springframework.org/schema/context
                       http://www.springframework.org/schema/context/spring-context-2.5.xsd">

<context:component-scan base-package="app.core" />

<bean id="viewResolver"
      class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/jsp/">
    </property>
    <property name="suffix" value=".jsp">
    </property>
</bean>

<bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
    <property name="defaultLocale" value="fr" />
</bean>

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

<mvc:resources mapping="/public/**" location="/WEB-INF/resources/"
               cache-period="31556926"/>

<mvc:annotation-driven />

</beans>

【问题讨论】:

    标签: spring maven properties messages resourcebundle


    【解决方案1】:

    来自the documentation

    基本名称遵循 ResourceBundle 约定:本质上是一个完全限定的 classpath 位置。如果它不包含包限定符(例如 org.mypackage),它将从 classpath 根目录解析。

    (强调我的)

    所以应该在src/main/resources下。

    【讨论】:

    • 成功了!谢谢 !即使我的 IDE(intellij 想法)警告 basename 值。
    猜你喜欢
    • 2016-02-23
    • 1970-01-01
    • 1970-01-01
    • 2021-07-05
    • 1970-01-01
    • 2017-11-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多