Reputation: 21194
Is it possible to ascertain whether a bean is a prototype bean or not?
I'm hoping for a method on one of the variants of application Context like getScope or getBeanMetaData...
Upvotes: 7
Views: 4250
Reputation: 120851
You can "ask" the BeanFactory
for the BeanDefintion
, it contains the scope
@Autowired
ConfigurableApplicationContext applicationContext;
...
applicationContext.getBeanFactory().getBeanDefinition("beanName").getScope()
(getBeanFactory()
is defined at ConfigurableApplicationContext
which is an interface that is implemented by every concrete ApplicationContext except StubWebApplicationContext
)
Upvotes: 12