在spirng中,现在在dao层写了三个接口,分别用来写数据库。这三个接口在服务层的接口实现里调用,我想为这个接口配置事务,在spring里应该是可以实现的吧?具体怎么配置,只有一点模糊的概念。大家给我个例子吧。

解决方案 »

  1.   

    看spring官方文档去 要学会自己查资料 解决问题
      

  2.   

    可以的 你可以把这个方法用特定的字符开头
    类似于下面的:<!-- transactionManager -->
    <bean id="transactionManager"
    class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory">
    <ref bean="sessionFactory" />
    </property>
    </bean>
    <bean id="baseTransactionProxy"
    class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
    abstract="true">
    <property name="transactionManager" ref="transactionManager" />
    <property name="transactionAttributes">
    <props>
    <prop key="do*">PROPAGATION_REQUIRED,-Exception</prop>
    <prop key="list*">PROPAGATION_REQUIRED,readOnly</prop>
    <prop key="set*">PROPAGATION_REQUIRED,readOnly</prop>
    <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
    <prop key="update*">PROPAGATION_REQUIRED,-Exception</prop>
    <prop key="save*">PROPAGATION_REQUIRED,-Exception</prop>
    <prop key="find*">PROPAGATION_REQUIRED,-Exception</prop>
    <prop key="change*">PROPAGATION_NESTED,-Exception</prop>
    </props>
    </property>
    </bean>