context in java

Context in java has been confusing me as to what it is. Recently, I have been free to consult some information, and combined with some of my own examples, I can understand it as follows:

The so-called context is a space (that is, a scope) that stores information globally. Such as ServletContext, it exists when the service is started, and it is released when the service is closed. All users share the information in the ServletContext.

Spring's context WebApplicationContext, where the bean is obtained

WebApplicationContext wac=(WebApplicationContext)req.getServletContext().getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);  
        wac.getBean("controllerBean")

The above code obtains the bean named controllerBean, which can be understood as obtaining the bean named controllerBean in the scope of WebApplicationContext.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324443953&siteId=291194637