Maybe I'm missing something, but isn't there any class that provides Scope.PROTOTYPE, Scope.SINGLETON
static references?
Or do I always have to use non-typesafe strings as scopes?
@Scope("prototype")
@Scope("singleton")
According to the Scope's documentation, the value
element is of type String
, not some enum constant. Hence we're searching for a class, where the possible values for the value
element are exposed.
BeanDefinition is the class you're looking for. It provides several public static String
fields, but you might be interested in these two:
SCOPE_SINGLETON
SCOPE_PROTOTYPE
And for example, they can be used like:
@Scope(value = BeanDefinition.SCOPE_PROTOTYPE)
I would advice for re-using them, instead of setting Strings literals all the time, as you might do some typo.
Constants that you can use to avoid literal Strings are:
ConfigurableBeanFactory.SCOPE_SINGLETON
ConfigurableBeanFactory.SCOPE_PROTOTYPE
WebApplicationContext.SCOPE_REQUEST
WebApplicationContext.SCOPE_SESSION
source: http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/context/annotation/Scope.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With