Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Controller's life-cycle in Spring MVC

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.

like image 812
flybywire Avatar asked Sep 26 '09 19:09

flybywire


People also ask

What is Spring MVC life cycle?

The Spring Web MVC framework provides Model-View-Controller (MVC) architecture and ready components that can be used to develop flexible and loosely coupled web applications.

Can Spring MVC define how many controller's )?

In Spring MVC, we can create multiple controllers at a time. It is required to map each controller class with @Controller annotation. Here, we see a Spring MVC example of multiple controllers.

What is bean life cycle in spring?

Bean life cycle is managed by the spring container. When we run the program then, first of all, the spring container gets started. After that, the container creates the instance of a bean as per the request, and then dependencies are injected. And finally, the bean is destroyed when the spring container is closed.


1 Answers

Here's a view of the lifecycle:

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

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.

like image 161
duffymo Avatar answered Sep 23 '22 00:09

duffymo