spring强行注入和引用实例解析
时间:2021-04-23 09:29:58|栏目:JAVA代码|点击: 次
这篇文章主要介绍了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);
上一篇:Java遍历Map对象的四种方式
栏 目:JAVA代码
下一篇:Java中流的有关知识点详解
本文标题:spring强行注入和引用实例解析
本文地址:http://www.codeinn.net/misctech/107265.html


阅读排行
- 1Java Swing组件BoxLayout布局用法示例
- 2java中-jar 与nohup的对比
- 3Java邮件发送程序(可以同时发给多个地址、可以带附件)
- 4Caused by: java.lang.ClassNotFoundException: org.objectweb.asm.Type异常
- 5Java中自定义异常详解及实例代码
- 6深入理解Java中的克隆
- 7java读取excel文件的两种方法
- 8解析SpringSecurity+JWT认证流程实现
- 9spring boot里增加表单验证hibernate-validator并在freemarker模板里显示错误信息(推荐)
- 10深入解析java虚拟机




