applicationContext.xml里的配置如下 <bean id="login" class="com.action.LoginAction">
<property name="employeeService"><ref bean="employeeService"/> </property>
</bean>
<bean id="employeeService" class="com.imp.EmployeeService">
<property name="sessionFactory"><ref bean="sessionFactory"/> </property>
</bean>对应com.action.LoginAction有如下一个变量
private EmployeeService employeeService;
其中com.imp.EmployeeService 继承了一个接口
public class EmployeeService implements EmployeeServiceInter
这样在运行时候系统会报错,说是EmployeeServiceInter格式无法转为EmployeeService 将配置文件里的代码改为如下代码则一切正常。本来被引用的bean类就是EmployeeService而在引用的类里建立一个EmployeeService格式的变量不就可以吗?为什么要在引用的类里建立一个EmployeeServiceInter格式的变量
<bean id="login" class="com.action.LoginAction">
<property name="EmployeeServiceInter"><ref bean="employeeService"/> </property>
</bean>
<bean id="employeeService" class="com.imp.EmployeeService">
<property name="sessionFactory"><ref bean="sessionFactory"/> </property>
</bean>
对应com.action.LoginAction变量改为 private EmployeeServiceInter employeeServiceInter;
springbeanclass
<property name="employeeService"><ref bean="employeeService"/> </property>
</bean>
<bean id="employeeService" class="com.imp.EmployeeService">
<property name="sessionFactory"><ref bean="sessionFactory"/> </property>
</bean>对应com.action.LoginAction有如下一个变量
private EmployeeService employeeService;
其中com.imp.EmployeeService 继承了一个接口
public class EmployeeService implements EmployeeServiceInter
这样在运行时候系统会报错,说是EmployeeServiceInter格式无法转为EmployeeService 将配置文件里的代码改为如下代码则一切正常。本来被引用的bean类就是EmployeeService而在引用的类里建立一个EmployeeService格式的变量不就可以吗?为什么要在引用的类里建立一个EmployeeServiceInter格式的变量
<bean id="login" class="com.action.LoginAction">
<property name="EmployeeServiceInter"><ref bean="employeeService"/> </property>
</bean>
<bean id="employeeService" class="com.imp.EmployeeService">
<property name="sessionFactory"><ref bean="sessionFactory"/> </property>
</bean>
对应com.action.LoginAction变量改为 private EmployeeServiceInter employeeServiceInter;
springbeanclass
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货