软件编程
位置:首页>> 软件编程>> java编程>> spring强行注入和引用实例解析

spring强行注入和引用实例解析

作者:蔡徐坤1987  发布时间:2021-11-23 23:26:19 

标签: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);

来源:https://www.cnblogs.com/charkey/p/10967839.html

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com