ConfigurableListableBeanFactory

ConfigurableListableBeanFactory

我正在尝试以下代码:

ConfigurableListableBeanFactory factory = ((AbstractRefreshableApplicationContext) applicationContext)
            .getBeanFactory();
factory.getDependenciesForBean(beanName)


但是我正面临着这个错误。

java.lang.ClassCastException: org.springframework.context.support.GenericApplicationContext cannot be cast to org.springframework.context.support.AbstractRefreshableApplicationContext


请提供您宝贵的意见,以防万一您遇到此问题,我该怎么办?

最佳答案

这有效

ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("context.xml");
ConfigurableListableBeanFactory bf = ctx.getBeanFactory();
bf.getDependenciesForBean(beanName)

09-28 09:58