6

Assuming a class is annotated with @Service, does Spring guarantee a unique instance of the class for injection? Or should I put @Scope("singleton") on every service?

Maciej Ziarko
  • 11,494
  • 13
  • 48
  • 69
Jérôme Verstrynge
  • 57,710
  • 92
  • 283
  • 453

2 Answers2

10

From the docs

The singleton scope is the default scope in Spring

So there is no need to set this explicitly.

Reimeus
  • 158,255
  • 15
  • 216
  • 276
1

Here is a discussion I found on CodeRanch:

http://www.coderanch.com/t/586038/Spring/Spring-treat-Service-Singleton

And an answer from a different Stackoverflow post:

https://stackoverflow.com/a/2173019

Community
  • 1
  • 1
Philip Tenn
  • 6,003
  • 8
  • 48
  • 85