spring2.0以后声明式事务管理

基于注解式的

<?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:tx="http://www.springframework.org/schema/tx"
     xsi:schemaLocation="
   http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
   http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

     <bean id="sessionFactory"
         class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource">
             <ref bean="dataSource" />
        </property>
        <property name="mappingResources">
             <list>
                 <value>com/goodhope/icbc/server/domain/Tuser.hbm.xml</value>
                 <value>com/goodhope/icbc/server/domain/WithDrawData.hbm.xml</value>
             </list>
         </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect"> org.hibernate.dialect.PostgreSQLDialect </prop>
                <prop key="hibernate.query.substitutions"> true 1, false 0 </prop>
                <prop key="hibernate.show_sql">true</prop>
            </props>
        </property>
     </bean>
   
    <!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) -->
        <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
         <property name="sessionFactory">
            <ref local="sessionFactory" />
            </property>
        </bean>

        <tx:annotation-driven/>   
</beans>

在类或者方法上使用
@Transactional(rollbackFor={SatusException.class,NOEnoughException.class})
posted @ 2008-10-29 17:35  Earl_86  阅读(141)  评论(0编辑  收藏  举报