The difference between the Contextloaderlistener and the ApplicationContext loaded by Dispatcherservlet

Source: Internet
Author: User

First Configuration Method:<servlet>      <servlet-name>dispatcher</servlet-name>       <servlet-class>org.springframework.web.servlet.DispatcherServlet< /servlet-class>      <init-param>           <param-name>contextConfigLocation</param-name>           <param-value>classpath*:applicationContext*.xml</param-value>       </init-param>      <load-on-startup >1</load-on-startup>  </servlet>  <servlet-mapping>       <servlet-name>dispatcher</servlet-name>      < url-pattern>*.do</url-pattern>  </servlet-mapping>  Second Configuration Method:<context-param> <param-name>contextconfiglocation</param-name><param-value>classpath:applicationcontext.xml,classpath:* Applicationcontext-*.xml</param-value></context-param><listener><listener-class> org.springframework.web.context.contextloaderlistener</listener-class></listener>  Difference: When the context loaded in Contextloaderlistener is successful, spring stores applicationcontext in ServletContext with the key value " Org.springframework.web.context.WebApplicationContext.ROOT "in the attribute. Dispatcherservlet if the value of the Publishcontext property is set to True after the context of the load has been successfully (true by default) The applicationcontext will be stored in the attribute of Org.springframework.web.servlet.FrameworkServlet.CONTEXT. + (Servletname). Conclusion: From the above analysis, it can be seen that the applicationcontext loaded by Dispatcherservlet can be considered as the private context of MVC, Because the key value stored in ServletContext is not the same as the key value that is used by the ApplicationContext loaded through Contextloaderlistener, So if you only use Dispatcherservlet to load the context, if there are places in the program that use Webapplicationcontextutils.getrequiredwebapplicationcontext ( ServletContext) to try to get Applicati

The difference between the Contextloaderlistener and the ApplicationContext loaded by Dispatcherservlet

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.