控制器在Spring MVC中的生命周期 [英] Controller's life-cycle in Spring MVC

查看:427
本文介绍了控制器在Spring MVC中的生命周期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Spring MVC中Controller的生命周期是什么?

What is the lifecycle of a Controller in Spring MVC?

何时创建控制器,何时销毁?它是在多个线程之间共享的吗?是否可以同时使用多个请求。

When is the controller created, when destroyed? Is it shared among multiple threads? Can it be in use simultaneously by more than one request.

推荐答案

以下是生命周期的视图:

Here's a view of the lifecycle:

http://www.flickr .com / photos / 60896767 @ N00 / 89101625 / sizes / l /

是的,它们由线程/请求共享;你应该把它们写成线程安全的。他们应该是无国籍的。通常他们会引用一个完成所有工作的Spring服务。控制器处理Web层的绑定,验证和路由。

Yes, they're shared by threads/requests; you should write them to be thread-safe. They should be stateless. Usually they have a reference to a Spring service that does all the work. Controllers handle binding, validation, and routing for the web tier.

这篇关于控制器在Spring MVC中的生命周期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆