There are many Dependency Injection (DI) methods such as declare bean in XML, @annotation, setter or constructor.. etc.
The HttpSession
without any DI method like above, how does it inject into Spring context?
I saw lots of codes that inject HttpSession
or Request directly by @Autowired
like below:
@Controller
public class MyController{
@Autowired
private HttpSession session;
@RequestMapping("/hello")
return "hello world";
}
I can't understand how does the HttpSession
inject into the controller without any bean injected into context.xml
or annotated by @Component
.
Can anyone give me the detail of the reason or link about that?
A: method "registerWebApplicationScopes" in WebApplicationContextUtils.java registers such HttpRequest by ConfigurableListableBeanFactory. Also, the method findAutowiredCandicate in DefaultListableBeanFactory shows how does such beans inject into spring context.