Are Spring MVC Controllers Singletons?

Solution 1:

Spring controllers are singletons (there is just one instance of each controller per web application) just like servlets. Typically there is no point in changing this behaviour (if it's even possible). See Regarding thread safety of servlet for common pitfalls, also applying to controllers.

If your application is clustered do as much as you can to avoid state. State in controllers will require synchronization to avoid threading issues. Also you'll probably replicate that state across servers - very expensive and troublesome.

Solution 2:

By default, Spring beans are singletons. Spring suggests to use singletons for stateless beans like controllers and DAOs, and prototype scope for stateful beans.

Solution 3:

The Struts2 Actions are not singletons because they carry state. Struts2 leverages javabeans properties on the action itself to carry the incoming request data and expose it to the various layers of the framework.

Spring, on the other hand, uses a model object that is handed to the controller. The controller itself doesn't hold state, so a singleton makes sense.