In what case would a programmer get the webApplicationContext out of DispatchServlet?
-
05-07-2019 - |
Question
I notice that there is getWebApplicationContext
in org.springframework.web.servlet.mvc.AbstractController
. This means that spring programmers can use getWebApplicationContext
to access beans in the spring IoC container.
However, I never see people use this way to get beans in all the spring MVC tutorials. So here comes my question, in that case would a programmer want to get the WebApplicationContext
?
Solution
That's an odd question... are you asking why a method is in the API if none of the tutorials use it? Do you expect every API method to be in the tutorials?
The getWebApplicationContext()
method is rarely used by application code, but it is used internally by Spring for some tasks.
OTHER TIPS
In some cases when you implement org.springframework.web.servlet.View
a call to getWebApplicationContext can be useful to get access to Spring beans that can not (or should not) be passed along in the Model
object.
You also might need it when implementing custom JSP tags to access Spring Beans e.g. But this is usually a method you try to avoid from application code.