Jan 23rd, 2012, 12:42 PM
inter-container dependency problem
i'm having problems with inter-container dependencies between a parent and child container when the parent is loaded in a ContextLoaderListener (needed for spring security) and the child is loaded in a DispatcherServlet.
For example: Spring Security OAuth2 context needs to be loaded in the ContextLoaderListener (because it needs to leverage the DelegatingFilterProxyfilter to execute the springSecurityFilterChain).
However, the problem here is that Spring Security OAuth2 provides a few @Controller classes. The @Controller classes are loaded in the parent container while the @EnableWebMCV Feature is enabled on the DispatcherServlet container. The result is that the Spring Security OAuth2 controllers are not available, which breaks the whole module. Moving the Spring Security OAuth2 configuration into the DispatcherServlet is not an option, because it then the springSecurityFilterChain is not available.
The same problem occurs also with TransactionManagement (as @Transactional methods are only woven in the container where the Feature is enabled) and is not related to Spring Security OAuth2 in particular.
A solution might be to load everything twice, but that seems a little silly. Maybe i don't understand the container concept. Any help on this subject would be much appreciated as I do not have any resolution to the problem.
Last edited by vonbrittelstrausse; Jan 23rd, 2012 at 12:56 PM.
Jan 23rd, 2012, 01:24 PM
Why would you need @Transactional in the dispatcherservlet any way? The dispatcher servlet should only contain web related beans and nothing else and your controllers shouldn't be the transactional layer, the service layer should be (and that should be in the contextloaderlistener).
Regarding the @Controller classes what is wrong with moving them simply to the dispatcherservlet? If that is a problem you can always configure the RequestMappingHandlerAdapter to also look in the parent context for @Controller annotated beans.
Jan 24th, 2012, 04:46 AM
Thanks for the answer Martin.
The @Transactional was merely a example to amend the problem, but point taken anyway.
Changing the RequestMappingHandlerAdapter to load the @Controller's from the parent context sounds good.
Jan 24th, 2012, 05:19 AM
Any pointers on how do load the @Controllers from the parent context? Does the default BeanFactory needs changing?
Jan 24th, 2012, 05:31 AM
DefaultAnnotationHandlerMapping has a detectHandlersInAncestorContexts property that enables the desired behaviour.