私は少し前にこれをしました。
Spring のドキュメントでは、 を使用しContextLoaderListener
てサーブレットのアプリケーション コンテキストをロードすることが推奨されています。この Spring クラスの代わりに、独自のリスナーを使用してください。ここで重要なことは、カスタム リスナーを Spring 構成で定義でき、それが定義されているアプリケーション コンテキストを認識できることです。したがって、新しいアプリケーション コンテキストをロードする代わりに、そのコンテキストを返すだけです。
リスナーは次のようになります。
public class CustomContextLoaderListener extends ContextLoaderListener implements BeanFactoryAware {
@Override
protected ContextLoader createContextLoader() {
return new DelegatingContextLoader(beanFactory);
}
protected BeanFactory beanFactory;
@Override
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
this.beanFactory = beanFactory;
}
}
はこれを行いDelegatingContextLoader
ます:
public class DelegatingContextLoader extends ContextLoader {
protected BeanFactory beanFactory;
public DelegatingContextLoader(BeanFactory beanFactory) {
this.beanFactory = beanFactory;
}
@Override
protected WebApplicationContext createWebApplicationContext(ServletContext servletContext, ApplicationContext parent) throws BeansException {
return new GenericWebApplicationContext((DefaultListableBeanFactory) beanFactory);
}
}
少し面倒で、おそらく改善される可能性がありますが、これは私にとってはうまくいきました。