aspose file tools*
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
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
Bartender

Joined: Jan 17, 2008
Posts: 2434
    
  28

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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Does Spring treat the @Service as a Singleton?