其他分享
首页 > 其他分享> > spring强行注入和引用的例子

spring强行注入和引用的例子

作者:互联网

前提:

public class DataProviderManagerImpl implements ApplicationContextAware

@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext;
}

  

强行注入:

//允许bean实例在所有的bean属性被设置时才能执行

if (provider instanceof InitializingBean) {
((InitializingBean) provider).afterPropertiesSet();
}

applicationContext.getAutowireCapableBeanFactory().autowireBean(provider);

  

强行引用: --就是普通的GetBean

InnerAggregator innerAggregator = applicationContext.getBean(H2Aggregator.class);

  

标签:强行,applicationContext,spring,class,bean,引用,provider,public
来源: https://www.cnblogs.com/charkey/p/10967839.html