2012-04-15 169 views
1

我開發了一個簡單的Spring應用程序,這是我的大學任務。有3個配置文件:web.xml,core-context.xml,dispatcher-servlet.xml和1個具有默認屬性的文件,名爲messages.properties,位於/ WEB-INF /文件夾中。Spring ReloadableResourceBundleMessageSource配置

在我的應用我有ReloadableResourceBundleMessageSource以下配置和正常工作:

核心的context.xml

<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource"> 
    <property name="basenames" value="/WEB-INF/messages" /> 
    <property name="useCodeAsDefaultMessage" value="true" /> 
</bean> 

的web.xml

<context-param> 
    <param-name>contextConfigLocation</param-name> 
    <param-value>classpath*:core-context.xml</param-value> 
</context-param> 
<servlet> 
    <servlet-name>dispatcher</servlet-name> 
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
    <load-on-startup>1</load-on-startup> 
</servlet> 

但事實證明,我的任務指示說我應該配置在dispatcher-servlet.xml中的ReloadableResourceBundleMessageSource bean。問題是,無論何時從core-context.xml中刪除上述配置並將其放入dispatcher-servlet.xml中,我的本地都不再顯示。

您能向我解釋爲什麼會出現問題嗎? 將bean配置放入core-context.xml和dispatcher-servlet.xml之間有什麼區別?

回答

0

你還沒有發佈你的dispatcher-servlet.xml,但我相信它沒有被spring容器初始化,因爲它沒有被聲明在任何地方。如果您必須指定另一個名爲dispatcher-servlet.xml的文件,那麼您可以將其導入到core-context.xml中。這應該可以解決你的問題。