Spring框架:在区域代码下未找到消息


问题内容

这是我的留言资源声明

<?xml version="1.0" encoding="UTF-8"?>

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

    <!-- Auto-detect controllers in this package -->
    <context:component-scan base-package="levelup.world.web" />

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

    <!-- Access resource bundles with the specified basename -->
    <bean id="messageSource"
        class="org.springframework.context.support.ReloadableResourceBundleMessageSource"
        p:basename="/WEB-INF/messages/" />

</beans>

当我运行我的应用程序时,出现此错误

No message found under code 'country.plural' for locale 'fil_PH'

现在在web-inf的我的邮件文件夹中,我具有以下邮件属性

messages_en.properties
messages_fr.properties
messages.properties

我在这里想念什么?


问题答案:

通常,出现此问题的原因不是因为不存在区域设置,而是因为MessageBundle配置不正确。在您的情况下,您似乎需要在基本名称中删除“ /”。

<bean id="messageSource"
     class="org.springframework.context.support.ReloadableResourceBundleMessageSource"
     p:basename="/WEB-INF/messages" />

为什么会这样:

如果您有messages.propertiesand
messages_en.properties捆绑包,那么捆绑包名称为messages。如果您在WEB- INF文件夹中有它们,则基本名称为/WEB-INF/messages,即根据/
path/to/bundle/bundlename。如果messages.properties/WEB- INF/messages文件夹中,则对应的基本名称为/WEB-INF/messages/messages