Spring @Controller 生命周期
我是 Spring MVC 的新手,想知道它如何处理请求,更具体地说:
- 我想知道 Spring 如何处理请求 @Controller的生命周期涉及 Servlet 的那个?
- 我也想变得更好 了解什么是最好的 多线程的实践 环境(例如在 Servlet 中, 类属性是否可见 多个 HTTP 请求作为对象 从池中重复使用)?
I am new to Spring MVC and would like to know how it handles requests, more specifically:
- I would like to know how a Spring
@Controller's life cycle relates to
that of a Servlet? - I would also like to better
understand what are the best
practices for multi-threaded
enviornments (e.g. like in Servlets,
are class attributes visible to
multiple HTTP requests as objects are
reused from the pool)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
控制器(与任何 spring bean 一样)都有一个范围。
最好的情况是你的控制器应该是
singleton
范围。在这种情况下,它非常像 servlet,并且:如果您的控制器范围是
request
或session
,那么您可以拥有实例变量,并且在每个新请求/会话上创建控制器的实例。A controller (as any spring bean) has a scope.
At best your controllers should be of scope
singleton
. In that case it is very much like servlets, and:If your controller scope is
request
orsession
, then you can have instance variables, and an instance of the controller is created on each new request/session.