Assume we have defined a controller class which has @Controller
annotation only.
Inside the class, we have defined private @Autowired HttpServletRequest request;
variable.
Spring Controllers are Singleton. When we defined HttpServletRequest
as @Autowired
in a web-application, will it be an issue?
I read from a web-site that even though it is @Autowired
it just injects a proxy for the thread variable.
Is it true? In a multi-threaded environment can we use @Autowired
or passing HttpServletRequest
as a parameter to each method in the controller class would be the right approach?
Some websites says it is an issue and suggested to pass as a parameter whereas few say it will be an issue.
I don't understand which one is right.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…