How does Spring Dispatcher Servlet create Default beans without any predefined XML configuration file. (I am not talking of annotations).
If we don’t give any default:
1) Handler mapping object
2) Multipart Resolver
3) Theme Resolver etc…
in the XML configuration file, Spring automatically creates these beans.
How does Spring create these beans when there is no explicit declaration of these beans anywhere?
And once created are these default beans available in the Application Context? I mean can we get these beans with a call to getBean() method on the context object?
Check out
DispatcherServlet.initStrategies():You’ll note that
DispatcherServlettries to find existing beans with some fixed name and either uses default or nothing if non found.No resolver is used if no other resolver is configured.
Check out
AnnotationDrivenBeanDefinitionParser.parse()– quite complex, be warned.FixedThemeResolveris used if no other resolver is configured.The internals of Spring MVC context startup are too complex for a reason – you should not mess around with them. Just supply callbacks or beans you want to replace.