Search code examples
springinstance-variables

Ambiguity with instance variable


I have one variable say 'x'.Now, i want 'x' should be visible to multiple methods in spring controller class.So i made 'x' as instance variable.Now if multiple users request the same controller , will 'x' creates any ambiguity.If it is, what is the best way to accomplish my need.

And I also got to know that we can make spring controller scope as per request.But Is there any drawback if we create new controller instance per every user request.


Solution

  • Why do you want to hold state in a controller ? Leave it as a singleton and if necessary inject in session or request scoped beans.