或者,以不同的方式 - 使用自动装配更好:
@Autowired
private BeanFactory beanFactory;
或实施BeanFactoryAware
:
@Configuration
public class MyConfigurationClass implements BeanFactoryAware {
private BeanFactory beanFactory;
@Override
public void setBeanFactory(final BeanFactory beanFactory) throws BeansException {
this.beanFactory = beanFactory;
}
}
是否有任何差异(除了设置BeanFactory实例的阶段)?