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
  • 10,624
  • 13
  • 47
  • 69
Jérôme Verstrynge
  • 55,046
  • 88
  • 271
  • 437

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
  • 155,977
  • 14
  • 207
  • 269
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
  • 5,815
  • 8
  • 46
  • 79