Now I have all EndPoint processed in one RestController, which contains about five for Autowire services. Is it that it turns out that for each request a new controller will be created and services will be uploaded to it that are not needed for this request at all?

In general, it seemed to me not very rational. Is there any BestPractice on this issue?

  • one
    And why did you decide that for each request a new controller is created? And, by the way, setting up links to services is a very simple operation (unless of course services are singletones). - Vladimir Parfenov
  • @VladimirParfenov Well, yes, it is probably not how I put it, there is likely a pool of controller objects. If the default service is singleton, then for me they are singletones. - droid

1 answer 1

In Spring, all controllers are singletons, which are also thread-safe. How exactly, I can not answer, because that technology did not plunge into such jungle.
So, for each request will not create a new instance of the controller. Yes, it is illogical in terms of performance. Feel free to leave your current logic and not be afraid to lose in performance.