Saturday 15 May 2010

java - Spring Interceptors configured in root ApplicationContext cannot be reached from child WebApplicationContext -



java - Spring Interceptors configured in root ApplicationContext cannot be reached from child WebApplicationContext -

ok understand fact web application context configured through dispatcherservlet inherits beans defined in root webapplicationcontext. nevertheless have configured interceptors in root applicationcontext

<bean class="org.springframework.web.servlet.mvc.annotation.defaultannotationhandlermapping"> <property name="order" value="2"/> <property name="interceptors"> <list> <ref bean="statisticsinterceptor"/> <ref bean="sessiondiagnosticsinterceptor"/> ...

then in web.xml have this:

<listener> <listener-class>org.springframework.web.context.contextloaderlistener</listener-class> </listener> <context-param> <param-name>contextconfiglocation</param-name> <param-value> /web-inf/applicationcontext*.xml </param-value> </context-param> <servlet> <servlet-name>dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class> <init-param> <param-name>contextconfiglocation</param-name> <param-value></param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet> <servlet-name>dispatcher-api</servlet-name> <servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class> <init-param> <param-name>contextconfiglocation</param-name> <param-value>/web-inf/appothercontext.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dispatcher</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>dispatcher-api</servlet-name> <url-pattern>/example/apiother/*</url-pattern> </servlet-mapping>

so problem have every time go url contains "/example/apiother/", interceptors not reached/run. question is: why? scope of handlermapping? thought because in root applicationcontext should apply kid contexts. i've been doing research , think handlermappings limited context if root context. right?

as configure interceptors through defaultannotationhandlermapping, used controllers in same applicationcontext. can (even not nice) declare interceptors in root application context, provided defaultannotationhandlermapping referes them declared in servlet application context declare controllers, either straight or through annotations.

java spring spring-mvc interceptor applicationcontext

No comments:

Post a Comment