• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

spring mvc singleton="false DAO issues?

 
selva raja
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear all,

In spring mvc in my all dao implantation classes set scope is singleton="false". Is it correct approach or not? If it is correct ...When we need to set to all daos are set to singleton="true"?



Please clarify the same.

Thanks,
SR
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
selva raja wrote:Dear all,

In spring mvc in my all dao implantation classes set scope is singleton="false". Is it correct approach or not? If it is correct ...When we need to set to all daos are set to singleton="true"?



Please clarify the same.

Thanks,
SR


Well singleton="true" is a Spring 1.x xml configuration. In Spring 2.x and above there is a scope="" to change the scope from Singleton to any other scope. But as far as DAO/Repositories, they shouldn't be holding any state, therefore being a stateless object and best as a Singleton, since you only need one instance to handle all your users. Many threads can call the same method at the same time in a single instance without any issues. It is only when you hold state that you have to think of Threading issues.

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic