The first type:
Some beans in the spring configuration file are usually called with ApplicationContext, so the spring context container is created first.
ApplicationContext AC = (applicationcontext) invocation.getinvocationcontext (). Getapplication (). Get ( Webapplicationcontext.root_web_application_context_attribute);
The invocation in the above code is the parameter of the Struts2 Interceptor method intercept (Actioninvocation invocation) method
Where Root_web_application_context_attribute is defined in the source code:
String Root_web_application_context_attribute = WebApplicationContext.class.getName () + ". ROOT ";
So this way you can get ApplicationContext
The second type:
ServletContext Sc=servletactioncontext.getservletcontext ();
ApplicationContext Ctx=webapplicationcontextutils.getwebapplicationcontext (SC);
Get the servlet context first (this is one of the three ways that Struts2 accesses the servlet)
Spring provides us with a convenient access to the Webapplicationcontext Webapplicationcontext tool class, which is easier than the previous one,
But if you look closely at the source of Webapplicationcontextutils's Getwebapplicationcontext (ServletContext SC), you will find that you will still use Root_web_application_ Context_attribute, so it boils down to the same principle.
public static Webapplicationcontext Getwebapplicationcontext (ServletContext SC) {
Return Getwebapplicationcontext (SC, webapplicationcontext.root_web_application_context_attribute);
}
How to call the Spring container in a Struts2 interceptor