【发布时间】:2017-02-15 15:53:07
【问题描述】:
我尝试使用Mkyong's guide 访问外部属性文件,但没有成功。
这是我在位于 WEB-INF 的 web-osgi-context.xml 文件中的 bean 定义:
<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 文件。它们包含以下行:
customer.name=Test, age : {0}, URL : {1}
这就是我所拥有的,我错过了什么吗?我得到的信息是:
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)
顺便说一句,我也尝试了内部属性,也没有成功。我在本地 servicemix(6.1.1) 中部署我的 .war,我还使用 wicket (6.24.0) 和 spring (3.2.14)。在本地运行 mkyong 的应用程序(不是 Web 应用程序)(无需在我的本地 servicemix 上部署它)。
【问题讨论】:
-
看来问题出在ServiceMix上。我会把它添加到标签中,希望有 ServiceMix 经验的人能提供帮助。
-
嗯,我认为这主要是因为它是一个 Web 应用程序,而不仅仅是字符串应用程序。尚未在 Web 应用程序中本地测试 mkyongs 方法
标签: spring javabeans cglib wicket-6 apache-servicemix