How can I assure that a Spring bean is a singleton?
I’d implement the Interfaces ApplicationContext, InitializingBean and BeanNameAware.
In afterPropertiesSet() I’d call isSingleton(String) with the Bean’s name.
Is there another way to make sure that a Bean is a singleton?
Because according to the API:
Note that it is not usually recommended that an object depend on its
bean name, as this represents a potentially brittle dependence on
external configuration, as well as a possibly unnecessary dependence
on a Spring API.
If i recall correctly, a spring-managed bean will be a singleton by default (for current versions of the spring-library), unless you define the scope to be of type ‘prototype’.
Check: Default scope of spring beans
Quote: