我想我的類路徑設置遇到了錯誤。在Junit測試中使用來自WEB-INF的i18n資源
我想測試一個國際化的網絡應用程序,它具有像這樣定義的MessageSource的:
<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basenames">
<list>
<value>/WEB-INF/i18n/errors</value>
<value>/WEB-INF/i18n/messages</value>
<value>/WEB-INF/i18n/links</value>
<value>/WEB-INF/i18n/forms</value>
<value>/WEB-INF/i18n/communication</value>
</list>
</property>
</bean>
裝載這些數值完全在生產環境中。 但是,運行Junit測試時,它不能解析這些屬性文件,因爲它們不在類路徑中。
不過,我想他們是不是在classpath中,因爲這樣我可以利用該功能,我可以更改屬性文件的東西,它反映立即在網站上:Since application servers typically cache all files loaded from the classpath, it is necessary to store resources somewhere else (for example, in the "WEB-INF" directory of a web app). Otherwise changes of files in the classpath will not be reflected in the application.
Spring的ApplicationContext是位於有:/src/main/resources/spring/applicationContext.xml
並裝入JUnit測試這些註釋:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:/spring/applicationContext.xml"})
我怎樣才能得到JUnit來拿起這些非類路徑的資源呢? 屬性文件在/src/main/webapp/WEB-INF/i18n/*
Junit:4.7。
Spring:3.0.5。