Spring框架:在区域代码下未找到消息 [英] Spring framework: No message found under code for locale
问题描述
这是我的messageResource声明
This is my messageResource declaration
<?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>
运行应用程序时,出现此错误
When I run my application, this error shows up
No message found under code 'country.plural' for locale 'fil_PH'
现在在web-inf的我的邮件文件夹中,我具有以下邮件属性
now inside my messages folder inside web-inf, I have the following message properties
messages_en.properties
messages_fr.properties
messages.properties
我在这里想念什么?
推荐答案
通常,出现此问题的原因不是因为不存在区域设置,而是因为MessageBundle
配置不正确.就您而言,您似乎需要在基本名称中删除"/".
In general such issue appears not because of non-existence locale, but because MessageBundle
is configured improperly. In your case you seem to need to remove "/" in your basename.
<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource"
p:basename="/WEB-INF/messages" />
为什么会这样:
如果具有messages.properties
和messages_en.properties
包,则包名称为messages
.如果将它们放在WEB-INF
文件夹中,则基本名称为/WEB-INF/messages
,即根据/path/to/bundle/bundlename
.如果/WEB-INF/messages
文件夹中有messages.properties
,则对应的基本名称为/WEB-INF/messages/messages
.
If you have messages.properties
and messages_en.properties
bundle, then bundle name is messages
. If you have them in the WEB-INF
folder, then basename is /WEB-INF/messages
, i.e. according to /path/to/bundle/bundlename
. If you have messages.properties
within /WEB-INF/messages
folder, then corresponding basename is /WEB-INF/messages/messages
.
这篇关于Spring框架:在区域代码下未找到消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!