Spring ReloadableResourceBundleMessageSource bean无法找到外部属性 [英] Spring ReloadableResourceBundleMessageSource bean unable to find external properties
问题描述
I've tried to use the Mkyong's guide to access external properties file, without any success.
这是我在WEB-INF中的web-osgi-context.xml文件中的bean定义:
This is my bean definition in web-osgi-context.xml file located in WEB-INF:
<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basenames">
<list>
<value>classpath:bundles/resource</value>
<value>classpath:bundles/override</value>
<value>file:c:/test/messages</value>
</list>
</property>
<property name="cacheSeconds" value="10"/>
</bean>
访问bean:
@SpringBean
private ReloadableResourceBundleMessageSource messageSource;
尝试像这样提取消息:
String name = messageSource.getMessage("customer.name",
new Object[] { 28,"http://www.mkyong.com" }, Locale.US);
System.out.println("Customer name (English) : " + name);
我在C:/test/messages和C:/test文件夹中都有messages_en_US.properties文件.它们包含以下行:
I have messages_en_US.properties files in both C:/test/messages and C:/test folders. They contain following line:
customer.name=Test, age : {0}, URL : {1}
仅此而已,我想念什么吗?我收到的消息是:
That's all I have, am I missing something? The message I get is:
org.springframework.context.NoSuchMessageException: No message found under code 'customer.name' for locale 'en_US'.
at org.springframework.context.support.AbstractMessageSource.getMessage(AbstractMessageSource.java:155)
顺便说一句,我也尝试了内部属性,但也没有成功.我将.war部署在本地servicemix(6.1.1)中,还使用了wicket(6.24.0)和spring(3.2.14).在本地运行mkyong的应用程序(不是Web应用程序)(无需在我的本地servicemix上部署它).
Btw, I also tried internal properties, also without success. I deploy my .war in my local servicemix(6.1.1), I also use wicket (6.24.0) and spring (3.2.14). Running mkyong's application(which is not a web application) locally (without deploying it on my local servicemix works).
推荐答案
如此,我在某种程度上发现了问题并得到了解决.
Sooo I somewhat found the problem and got a workaroud..
这行不通:
<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename">
<value>classpath:messages</value>
</property>
</bean>
在代码中:
@SpringBean
private ReloadableResourceBundleMessageSource messageSource;
通过在此源上运行getClass()
By running getClass() on this source I get
class WICKET_org.springframework.context.support.ReloadableResourceBundleMessageSource$$EnhancerByCGLIB$$852b0c02
但这是可行的:
But this is working:
@Bean
public MessageSource messageSource() {
ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
messageSource.setBasename("classpath:messages");
return messageSource;
}
通过在此源上运行getClass()
By running getClass() on this source I get
class org.springframework.context.support.ReloadableResourceBundleMessageSource
Cglib增强程序是否有可能在这里搞乱了提要?有什么办法可以让我知道这一点吗?
Is it possible that Cglib enhancer is messing thigs up here? Any way I can make first option working knowing that?
这篇关于Spring ReloadableResourceBundleMessageSource bean无法找到外部属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!