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