I am using Spring framework. Should my service classes be created as singletons? Can someone please explain why or why not? Thanks!
I am using Spring framework. Should my service classes be created as singletons? Can
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes, they should be of scope
singleton.Services should be stateless, and hence they don’t need more than one instance.
Thus defining them in scope
singletonwould save the time to instantiate and wire them.singletonis the default scope in spring, so just leave your bean definitions as they are, without explicitly specifying thescopeattribute.You can read more about scopes in the spring docs.