Primarily used to get beans from application
1, ApplicationContext
Using the listener configuration in Web. xml
<context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath: applicationcontext.xml</param-value> </context-param> <listener> <listener-class >org.springframework.web.context.contextloaderlistener</listener-class> </listener>
Using Webapplicationcontext to get
Webapplicationcontext Webapplicationcontext =contextloader.getcurrentwebapplicationcontext ();
2, Springmvc-serlvet
Using the servlet configuration in Web. xml
<servlet> <servlet-name>springMVC</servlet-name> <servlet-class> org.springframework.web.servlet.dispatcherservlet</servlet-class> <init-param> < Param-name>contextconfiglocation</param-name> <param-value>classpath:springmvc-servlet.xml</ param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> < Servlet-mapping> <servlet-name>springMVC</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping>
Using ServletContext to get
ServletContext servletcontext== (webapplicationcontext) Servletcontext.getattribute ( Webapplicationcontext.root_web_application_context_attribute);
Reference: SPRINGMVC using Webapplicationcontext to get ApplicationContext objects
Springmvc using Webapplicationcontext to get ApplicationContext objects