This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes Spring and the fly likes Does Spring treat the @Service as a Singleton? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Does Spring treat the @Service as a Singleton?" Watch "Does Spring treat the @Service as a Singleton?" New topic
Author

Does Spring treat the @Service as a Singleton?

Sam Yim
Greenhorn

Joined: Jul 25, 2009
Posts: 17
If I have a class that is annotated with @Service, Spring create one instance of this to be shared in the JVM?

Or will every consumer class that autowires the service will get a new instance of the service?
Jayesh A Lalwani
Saloon Keeper

Joined: Jan 17, 2008
Posts: 2683
    
  31

By default Service annotation creates a singleton scoped bean. If you want to change the behavior, you have to annotate with @Scope
Sam Yim
Greenhorn

Joined: Jul 25, 2009
Posts: 17
Great. That was the expected behavior I hoped for. Thanks for the response.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Does Spring treat the @Service as a Singleton?
 
jQuery in Action, 3rd edition