我使用TransactionProxyFactoryBean生成了一个service的代理类,然后接收只能用service的接口,不能用实现类接收
IAccountService service = (IAccountService) context.getBean("serviceProxy");这样写就没问题,但是下面这样写就会报类型转换错误
AccountServiceImpl service = (AccountServiceImpl)context.getBean("serviceProxy");
而且既然不能转换为实现类,为什么又能明确的调用我希望的实现类中的方法?
下面是配置文件相关部分
<bean id="service" class="com.zuijianren.service.impl.AccountServiceImpl2">
<property name="dao" ref="dao"></property>
</bean>
<bean id="serviceProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<!--接口,可以不配-->
<!--代理对象-->
<property name="target" ref="service"></property>
<!--切面类,不用配置,spring自动完成-->
<!--事务管理器-->
<property name="transactionManager" ref="txManager"></property>
<!--transactionAttributes:事务属性/详情配置
key:写方法名
value:写事务配置
格式:PROPAGATION,ISOLATION,readOnly,-Exception,+Exception
传播行为 隔离级别 是否只读 异常回滚 异常提交
-->
<property name="transactionAttributes" >
<props>
<prop key="transfer">PROPAGATION_REQUIRED,ISOLATION_DEFAULT</prop>
</props>
</property>
</bean>
IAccountService service = (IAccountService) context.getBean("serviceProxy");这样写就没问题,但是下面这样写就会报类型转换错误
AccountServiceImpl service = (AccountServiceImpl)context.getBean("serviceProxy");
而且既然不能转换为实现类,为什么又能明确的调用我希望的实现类中的方法?
下面是配置文件相关部分
<bean id="service" class="com.zuijianren.service.impl.AccountServiceImpl2">
<property name="dao" ref="dao"></property>
</bean>
<bean id="serviceProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<!--接口,可以不配-->
<!--代理对象-->
<property name="target" ref="service"></property>
<!--切面类,不用配置,spring自动完成-->
<!--事务管理器-->
<property name="transactionManager" ref="txManager"></property>
<!--transactionAttributes:事务属性/详情配置
key:写方法名
value:写事务配置
格式:PROPAGATION,ISOLATION,readOnly,-Exception,+Exception
传播行为 隔离级别 是否只读 异常回滚 异常提交
-->
<property name="transactionAttributes" >
<props>
<prop key="transfer">PROPAGATION_REQUIRED,ISOLATION_DEFAULT</prop>
</props>
</property>
</bean>