ディスパッチャ サーブレットとその構成ファイルを動的にロードする必要があります。春のごく最近の開発である webapplicationinitializer を使用してディスパッチャーサーブレットを注入するという概念を検討しています。次のドキュメントで概要を説明しています: http://static.springsource.org/spring/docs/3.1.x/javadoc-api/org/springframework/web/WebApplicationInitializer.html
基本的なセットアップをしようとしていますが、うまくいきません。伝統的な春の開発からどこから離れ始めればよいのか理解できません。この新しいメカニズムの使用方法について、誰かが例を挙げて説明してくれますか? 次のコードを使用しました:
public class MyWebAppInitializer implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext container) {
// Create the 'root' Spring application context
AnnotationConfigWebApplicationContext rootContext =
new AnnotationConfigWebApplicationContext();
rootContext.register(AppConfig.class);
// Manage the lifecycle of the root application context
container.addListener(new ContextLoaderListener(rootContext));
// Create the dispatcher servlet's Spring application context
AnnotationConfigWebApplicationContext dispatcherContext =
new AnnotationConfigWebApplicationContext();
dispatcherContext.register(DispatcherConfig.class);
// Register and map the dispatcher servlet
ServletRegistration.Dynamic dispatcher =
container.addServlet("dispatcher", new DispatcherServlet(dispatcherContext));
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/");
}
}
さらに、dispatcher servlet を動的に注入している場合、dispatcher servlet は Web コンテナー (tomcat) の起動時に読み込まれるということですか?