以下のように、SpringBean定義ファイルがあります。
<bean id="jettyZk" class="org.eclipse.jetty.server.Server" init-method="start" destroy-method="stop">
<!-- properties, threadPool, connectors -->
<property name="handler">
<bean class="org.eclipse.jetty.servlet.ServletContextHandler">
<property name="eventListeners">
<list>
<!-- my.ContextLoaderListener
* An ApplicationContextAware ContextLoaderListener that allows for using the current ApplicationContext,
* as determined by ApplicationContextAware, as the parent for the Root WebApplicationContext.
*
* Also provides for specifying the contextConfigLocation of the Root WebApplicationContext, because
* Eclipse Jetty 7 ServletContextHandler does not expose a setInitParameters method.
-->
<bean class="my.ContextLoaderListener">
<property name="contextConfigLocation" value="/META-INF/spring/applicationContext-securityZk.xml"/>
</bean>
<!-- not sure if this is needed, disabled for now -->
<!-- <bean class="org.springframework.web.context.request.RequestContextListener"/> -->
</list>
</property>
<property name="servletHandler">
<bean class="org.eclipse.jetty.servlet.ServletHandler">
<property name="filters">
<list>
<bean class="org.eclipse.jetty.servlet.FilterHolder">
<property name="name" value="springSecurityFilterChain"/>
<property name="filter">
<bean class="org.springframework.web.filter.DelegatingFilterProxy"/>
</property>
</bean>
</list>
</property>
<!-- filterMappings, servlets, servletMappings -->
</bean>
</property>
</bean>
</property>
</bean>
コンテキストを開始しようとすると、次の例外が発生します
Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: ServletContext must not be null
Caused by: java.lang.IllegalArgumentException: ServletContext must not be null
at org.springframework.util.Assert.notNull(Assert.java:112)
at org.springframework.web.context.support.WebApplicationContextUtils.getWebApplicationContext(WebApplicationContextUtils.java:109)
これはSpring3.0.5.RELEASEを使用しています
DelegatingFilterProxy#findWebApplicationContextのコードとJavaDocsを見ると、例外は理解できます。
このフィルターが初期化(または呼び出される)される前に、WebApplicationContextがすでにロードされてServletContextに格納されている必要があります。
コンテキストハンドラーの(サブ)プロパティとしてフィルターを作成しようとしているため、コンテキストがまだ初期化されておらず、SpringWACも初期化されていないことが賢明であるように思われます。
私が知りたいのは、Spring自体が組み立てている組み込みJettyコンテナでSpring Securityを構成するにはどうすればよいですか?
遅い初期化が必要なキャッチ22シナリオがあるようですが、いじるのに適したフラグが見つかりません。フィルターBeanに設定lazy-init="true"
してみましたが、当然のことながら、それほど多くは達成されなかったようです。
関連: JettyをSpringに埋め込み、埋め込まれたのと同じAppContextを使用させるにはどうすればよいですか?