日期:2014-05-17  浏览次数:20616 次

请教spring @Service如何加Parent进行事物控制的问题,请不吝赐教
正在做的项目中,用的是spring2,项目中有一个配置文件,作了事物控制配置
<!-- metabase事务 -->
<bean id="transactionManagerRootProxy"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
abstract="true">
<property name="transactionManager">
<ref bean="metaTransactionManager"/>
</property>
<property name="proxyTargetClass">
<value>false</value>
</property>
<property name="transactionAttributes">
<props>
<prop key="insert*">PROPAGATION_REQUIRED,-Exception</prop>
<prop ke三y="update*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="select*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="remove*">PROPAGATION_REQUIRED,readOnly</prop>

</props>
</property>
</bean>
以前在写service时,是通过配置文件加parent进行事物控制,如
 <bean id="templateService" parent="transactionManagerRootProxy" >  
现在我想对service使用spring注释的方式
@Service
public class RptUserColumnServiceImpl implements RptUserColumnService
{

如何给这个Service类加上parent呢?请高人指点


------解决方案--------------------
XML code


<?xml version="1.0" encoding="UTF-8" ?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" 
xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd   
http://www.springframework.org/schema/context   
http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<context:annotation-config />
<!--注解式事务配置驱动-->
    <tx:annotation-driven transaction-manager="transactionManager"
        proxy-target-class="true" />
    <!--
        业务类bean的实现类标注了@Transactional注解,所以会被 tx:annotation-driven注解驱动自动织入事务增强
    -->

    <!-- 配置事务管理器 -->
    <bean id="transactionManager"
        class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory">
            <ref bean="sessionFactory" />
        </property>
    </bean>

    <!-- 使Spring关注Annotation -->
    <context:annotation-config />
    <context:component-scan base-package="com.xx.service" />
    <context:component-scan base-package="com.xx.service" />