Spring and SPRINGMVC related issues: ServletContext-parent-child container

Source: Internet
Author: User
Tags spring mvc tutorial

Summarized as follows:
    • defined in the servlet specification the role and significance of ServletContext. In addition to identifying multiple Web apps in a Tomcat, everyone web App has a unique ServletContext (Global context). [See: The same Tomcat multiple application session issue]
thisServletContext for built-in objects in JSPjavax.servlet.jsp. ServletContext (Acting onApplication global level )
  • Clear Spring (Spring.context package definition) Context The ApplicationContext object manages the entire spring life cycle as a container. ApplicationContext in a Web application requires a hosting environment ServletContext. In the process of launching the Web app during initialization (the servlet specification requires that the container be loaded to execute the associated Initxxxx method) spring uses the standard toContextloaderlistener (implements the listener Servletcontextlistener in the servlet specification so that it can bewhen ServletContext is created, the spring container is instantiated synchronously--ApplicationContext)
  • SPRINGMVC has its own context, and a dispacherservlet should have a context of its own.
  • we can understand that the spring context is a parent context, shared for all child contexts. A ServletContext can have a spring context (parent/root context root Web applicationcontext). There can be more than one servlet context (child context) within a spring context. The parent context cannot access child contexts, and child contexts are inaccessible to each other. A child context can access the parent context. Essentially Dispacherservlet is a servlet.
  • When Sevlet cannot find the managed bean in the current context, it looks in the parent context. Unlike a parent-child context usage scenario, a database connection, service layer can be placed in the parent context for the entire web app to be shared. Child contexts can manage their own build objects and data-sharing transmissions in Web presentation.
  • the configuration of spring and SPRINGMVC is in Web. Xml. Spring instantiates itself by implementing the Contextloaderlistener of Servletcontextlistener . SPRINGMVC instantiate itself through a servlet configuration.
  • Point of contention: If you do not configure Servletcontextlistener, only configure SPRINGMVC dispacherservlet case,  Dispacherservlet if the parent context is not found, then the parent context is created and associated with its own child context (creating its own context (child context) is positive). There seems to be a case of appeal. In practice, you can load your own and spring configuration files by Springmvc in the configuration file. in this way, the use of webapplicationcontextutils directly to the parent context is invalidated because the key ID in the binding to ServletContext is different. There is a question about how to get the parent context (ApplicationContext).
In the practice of modifying a configuration file to load spring and SPRINGMVC profiles only through SPRINGMVC, the project starts without an error, and errors occur after opening the Jeesite home page:
   
 
  1. 错误信息:No WebApplicationContext found: no ContextLoaderListener registered?
  2. 请点击“查看详细信息”按钮,将详细错误信息发送给系统管理员,谢谢!
  3. 返回上一页 查看详细信息
  4. 错误信息:
  5. java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener registered?
  6. at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:252)
  7. at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
  8. at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
The reason for this estimate is that SPRINGMVC can load the spring container, but this way you need to modify the relevant code in the original Jeesite code to use the parent.
In addition There are many confusing areas in everyday writing, such as Web application, which are Web applications. The context concept of layering resulting from SPRINGMVC intervention: The root context is actually springApplicationContext (context), corresponding to the Spring.context packageApplicationContext.the interface Webapplicationcontext in Springmvc is inherited by theSpring.context.ApplicationContext interface. During the SPRINGMVC initialization process, the view also associates its own child context with the parent context. For SPRINGMVC, its context (child context) is aThe webapplicationcontext type.The parent context created by Servletcontextlistener isThe applicationcontext type.when SPRINGMVC is associated, the parent context may beApplicationContextSwitchwebapplicationcontext for use.
  
 
  1. WebApplicationContext rootContext =
  2. Span class= "Typ" >webapplicationcontextutils getwebapplicationcontext ( getservletcontext ());
  3. the code inside is passed through the current servletcontext attribute ID: webapplicationcontext.root_web_application_context_attribute to Get Spring context (parent)
  4. It is converted from object to Webapplicationcontext for use.
  5. Of course when associating the parent context:CWAC. SetParent (rootcontext);
  6. The type here is also void SetParent (applicationcontext parent);
It is estimated that this is why the parent-child context becomes webapplicationcontext in some documents. For example, this diagram:
detailed reading is as follows:1 First understand what is ServletContext. Click: Servlet's ServletContext
ClickServletContext function and its embodiment in JSP and spring

2 Approximate Summary Click the relationship of Dispacherservlet, Webapplicationcontext, ServletContext in spring
3 Specific instructions Click in-depth analysis of spring and Spring MVC container-Taubonren
Click Springmvc Deep Adventure (iii)--dispatcherservlet and initialization mainline-Downpour-iteye technology website-360 Secure Browser 8.2
Look at the relationship between Springmvc and spring interface: Spring MVC tutorial, QuickStart, in-depth analysis-Technical Blog-Iteye technology website-360 Secure Browser 8.2
SOURCE reading: Click "Spring MVC" Spring MVC launch Process source Analysis-Program Park-360 Secure Browser 8.2








Null

Spring and SPRINGMVC related issues: ServletContext-parent-child container

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.