java - How exactly are the root context and the dispatcher servlet context into a Spring MVC web application? -
i studying spring mvc , have doubt related
so, have configuration class configure dispatcherservlet handle user requests:
public class mywebappinitializer implements webapplicationinitializer { @override public void onstartup(servletcontext container) { // create 'root' spring application context annotationconfigwebapplicationcontext rootcontext = ... // create dispatcher servlet's spring application context annotationconfigwebapplicationcontext dispatchercontext = new annotationconfigwebapplicationcontext(); dispatchercontext.register(dispatcherconfig.class); // register , map dispatcher servlet servletregistration.dynamic dispatcher = container.addservlet("main", new dispatcherservlet(dispatchercontext)); dispatcher.setloadonstartup(1); dispatcher.addmapping("main/"); } } it pretty clear me how dispatcherservlet works. doubts related context concept.
1) represent context? think set of beans have specific pourpose , works togheter environment. absolutly not true assertion.
2) difference between root context , dispatcher servlet context?
3) have understand beans defined in dispatchercontext have access beans defined in rootcontext (but opposite not true). why?
tnx
root context
the root-context in spring application applicationcontext loaded contextloaderlistener. context should have globally available resources services, repositories, infrastructure beans (datasource, entitymanagerfactorys etc.) etc.
the contextloaderlistener registers context in servletcontext under name org.springframework.web.context.webapplicationcontext.root.
if load applicationcontext , register name above in servletcontext qualify root-context.
child context
the child-context in spring application applicationcontext loaded dispatcherservlet (or instance messagedispatcherservlet in spring-ws application). context should contain beans relevant context, spring mvc viewresolvers, handlermappings etc.
the servlet registers context in servletcontext under name org.springframework.web.servlet.frameworkservlet.context.<servlet-name>.
root <-child relation
only child contexts have access parent context, because have multiple child contexts. instance in spring mvc combined spring ws application. parent-context detect childs finding in servletcontext known name.
if root context have access child 1 use wire beans? next if case surprising results when aop involved. aop defined in child context influence beans configured in root context.
Comments
Post a Comment