It's probably a dumb question for the experts in Spring MVC but I don't know how does it work under the hood that's why I ask.
Another wording for the same question: are there any dependencies on Spring DI inside Spring MVC?
I am pretty sure it's not possible to use Spring MVC without the IOC container.
For example: at the heart of Spring MVC lies the DispatcherServlet
. DispatcherServlet
initializes itself using these methods:
/**
* This implementation calls {@link #initStrategies}.
*/
@Override
protected void onRefresh(ApplicationContext context) {
initStrategies(context);
}
/**
* Initialize the strategy objects that this servlet uses.
* <p>May be overridden in subclasses in order to initialize
* further strategy objects.
*/
protected void initStrategies(ApplicationContext context) {
initMultipartResolver(context);
initLocaleResolver(context);
initThemeResolver(context);
initHandlerMappings(context);
initHandlerAdapters(context);
initHandlerExceptionResolvers(context);
initRequestToViewNameTranslator(context);
initViewResolvers(context);
}
So you can see, everything is tightly integrated with the ApplicationContext
interface.
So your only chance would be to have a Guice implementation of ApplicationContext, and that would be very far-fetched, I guess.
It should be possible to use some of the more primitive Spring MVC functionality without using the Spring IOC container - this is, after all, the whole point of IoC.
It's going to be difficult, though, since many of the Spring MVC components use the Spring-proprietary lifecycle callbacks (e.g. InitializingBean
and DisposableBean
) which Guice won't know about. You'd have to handle those yourself.
A better question, though, is why would you want to do this? Without Spring IoC being used, Spring MVC loses most of its appeal. I don't see why you would want to use one without the other.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With