接口:UserInfoService
业务类:UserInfoServiceBean实现UserInfoService1.关于强制转换private UserInfoService userService;
private UserInfoService service;
ApplicationContext cxt = new ClassPathXmlApplicationContext("beans.xml");
userService = (UserInfoServiceBean)cxt.getBean("userInfoServiceBean"); //①
service = (UserInfoService)cxt.getBean("userInfoServiceBean"); //②a.我使用①和②两种方法分别进行实例化,但是却发现有时会出现类型转换异常,这是为什么?
b.我将dataSource在多个bean中注入,不知是否与这个有关系?
c.使用接口强制转换与使用类强制转换有什么区别?2.关于Spring2.0
现在在学Spring 2.5,公司之前一直用自己的框架,想问下,还有必要去看Spring 2.0 吗?
业务类:UserInfoServiceBean实现UserInfoService1.关于强制转换private UserInfoService userService;
private UserInfoService service;
ApplicationContext cxt = new ClassPathXmlApplicationContext("beans.xml");
userService = (UserInfoServiceBean)cxt.getBean("userInfoServiceBean"); //①
service = (UserInfoService)cxt.getBean("userInfoServiceBean"); //②a.我使用①和②两种方法分别进行实例化,但是却发现有时会出现类型转换异常,这是为什么?
b.我将dataSource在多个bean中注入,不知是否与这个有关系?
c.使用接口强制转换与使用类强制转换有什么区别?2.关于Spring2.0
现在在学Spring 2.5,公司之前一直用自己的框架,想问下,还有必要去看Spring 2.0 吗?
用这个应该是可以转化的.因为代理默认形式是用接口的.
以下项目中的代码:仅供参考<bean id="interviewService" class="com.lxitedu.interview.logic.impl.InterviewServiceImpl">
<property name="interviewDao" ref="interviewDao"></property>
</bean>
你这样试试
还不成,所正对象拿到了,反射吧