是否可以在运行时检测CDI托管bean的范围?
答案 0 :(得分:1)
您可以注入BeanManager并查询您的bean定义:
@Inject
BeanManager beanManager;
...
Class<? extends Annotation> scope = beanManager.getBeans(MyClass.class,MyOptionalQualifier1.class).iterator().next().getScope();
if(scope.isAssignableFrom(RequestScoped.class))
...