Context--webapplicationcontext and ServletContext

Source: Internet
Author: User

1.WebApplicationContext of research

ApplicationContext is the core of spring, and the context is often interpreted as a contextual environment, with a "container" to make it easier to understand, and applicationcontext as "the container of application."

Spring puts the bean in this container and takes it out with the Getbean () method when needed, and in the Web application, it uses Webapplicationcontext, which inherits from ApplicationContext

In the Web. XML Initialization webapplicationcontext:

1    <Context-param>2 3            <Param-name>Contextconfiglocation</Param-name>4 5            <Param-value>/web-inf/applicationcontext.xml</Param-value>6 7   </Context-param>8 9 <Listener>Ten  One      <Listener-class>Org.springframework.web.context.ContextLoaderListener</Listener-class> A  - </Listener>

Or you can use Contextloaderservlert (plus <load-on-startup>1</load-on-startup>)

2.ServletContext explanation

ServletContext is an interface for direct communication between a servlet and a servlet container, and theservlet container creates a ServletContext object for it when it launches a Web application. Each web app has a unique ServletContext object that shares a single servletcontext with all the servlet objects of the same web Appthat the Servlet object can use to access the various resources in the container

Access shared Data method: SetAttribute (String name,object obj) getattribute (string name)

1 webapplicationcontext ctx=webapplicationcontextutils.getwebapplicationcontext (Request.getSession ( ). Getservletcontext ())       2 DataSource ds=    ctx.getbean (DataSource.  Class); 3  Jrexportservice.setdatasource (DS)

Here is the spring webapplicationcontext, the spring beans are put in the inside, and then directly Getbean can get

Context--webapplicationcontext and ServletContext

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.