Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 731 Vote(s) - 3.49 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Controller's life-cycle in Spring MVC

#1
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.

Reply

#2
Here's a view of the lifecycle:

[To see links please register here]


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.
Reply

#3
All controllers of Spring MVC are singleton. As other normal singleton beans, instance of controllers will be created after start of web application context and disposed before end of it.

Even you specify other scope (for example, prototype) for controller bean definition, because spring has some kind of cache for controllers for performance, only the first acquired instance of controller will be used repeatedly.

Reply

#4
Controllers are just beans, they can be singleton or prototype, it depends on what you are trying to do. If you want statefulness use prototype, by default they are singleton.

[To see links please register here]


Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through