赞
踩
假定:Son类实现father接口
在Son类定义声明式事务后
通过ApplicationContext接口的getBean(Class arg0)方法获取注入好的bean会报异常,方法参数Son.class,Son已声明bean.
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [cn.smbms.service.user.UserServiceImpl] is defined
使用getBean(Class arg0)方法,如果参数添加了声明式事务,要使用该class的父类作为参数
将getBean(Son.class)的参数改为Son.class改为Father.class
并且返回类型也必须强转为返回类型的接口或父类
即(Father)context.getBean(Father.class);
在没有定义声明式事务,可以直接使用getBean(Son.class)返回注入好的对象,不需要使用该beand的接口或父类作为参数.
ps.尚在学习中,暂且没有找到参考,只能先记录下来,等深入学习后再详细补全答案.也虚心向各位前辈请教.
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。