简体   繁体   English

如何找出spring托管bean的范围

[英]How to find out the scope of a spring managed bean

Is it possible to ascertain whether a bean is a prototype bean or not? 是否可以确定bean是否是原型bean?

I'm hoping for a method on one of the variants of application Context like getScope or getBeanMetaData... 我希望在应用程序上下文的一个变体上有一个方法,比如getScope或getBeanMetaData ......

You can "ask" the BeanFactory for the BeanDefintion , it contains the scope 您可以向BeanFactory “询问” BeanDefintion ,它包含范围

 @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 ) getBeanFactory()ConfigurableApplicationContext中定义, ConfigurableApplicationContext是由除StubWebApplicationContext之外的每个具体ApplicationContext实现的接口)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM