独自のContextLoaderを作成し、JUnitのクラスにこの注釈を付ける:
@ContextConfiguration(loader=YourLoader.class)
これは、順番に、カスタムたBeanFactory(能力に依存)で初期化されることができる別のまたはカスタムのApplicationContextをインスタンス化する私の例ローダーです: (スプリングフレームワークによって提供される)上記の場合アプリケーションのコンテキストにおいて
public class XmlWebApplicationContextLoader extends AbstractContextLoader {
public final ConfigurableApplicationContext loadContext(final String... locations) throws Exception {
ServletContext servletContext = new MockServletContext("war", new FileSystemResourceLoader());
GenericWebApplicationContext webContext = new GenericWebApplicationContext();
servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, webContext);
webContext.setServletContext(servletContext);
new XmlBeanDefinitionReader(webContext).loadBeanDefinitions(locations);
AnnotationConfigUtils.registerAnnotationConfigProcessors(webContext);
webContext.refresh();
webContext.registerShutdownHook();
return webContext;
}
protected String getResourceSuffix() {
return "";
}
}
コンストラクタを有します。
public GenericWebApplicationContext(DefaultListableBeanFactory beanFactory) {
super(beanFactory);
}
これは正確にどのように役立ちますか? ContextLoaderのSpringソースコードを読んでいて、BeanFactoryを受け入れることができないようです。そしてAFIK ContextLoader!= BeanFactory – krosenvold
あなたはどんなアプリケーションコンテキストタイプを使用していますか? GenericApplicationContextを新しいBFでインスタンス化し、カスタムローダのloadContextメソッドでそれを返すことができます。 – gertas
私には見えます。 ContextLoaderは、文字列の配列をアプリケーションコンテキストに変換する方法を指定するインタフェースです。 – Pace