私はクラスパス設定でエラーが発生したと思います。JunitテストでWEB-INFのi18nリソースを使用する
<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>
これらの値をロードする本番環境で完璧に動作します:
は、私はこのように定義されたmessagesourceを持っている国際ウェブアプリをテストしたいです。 ただし、Junit Testを実行すると、クラスパスにないため、これらのプロパティファイルを解決できません。
しかし、私はその後、私はプロパティファイルで何かを変更することができ、それはすぐにウェブサイトに反映されます機能を利用することができますので、それらをクラスパス上にないようにしたい: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.
春の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です。
春:3.0.5。