Thinking of Injecting HttpServletRequest Member Variables into Spring Bean

When using the spring framework to develop, we often encounter this situation: that is, multiple methods in a @Controller or @Service use the request parameter, so in order to simplify the code, we will inject request as a member variable .
However, if you think about it carefully, we will have this question:

@Controller in spring is singleton by default, and its member variables are also injected during bean initialization. The variable HttpServletRequest is different for each request. Does @Controller reinject the member variable request for each request? Not to mention that this approach does not conform to Spring's general approach to bean management. Even if this is done, how to ensure thread safety?

Original link: https://www.jianshu.com/p/bcc3d3b9686a

Guess you like

Origin blog.csdn.net/qq_28807077/article/details/109629211