• Spring的声明式事务


    1.与hibernate集成
    <bean id="sessionFactory"   class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> 
       <property name="configLocation" value="classpath:hibernate.cfg.xml"> </property> 
    </bean> 
    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> 
       <property name="sessionFactory"><ref bean="sessionFactory" /></property> 
    </bean> 
     <!--支持@Transactional标记--> 
    <tx:annotation-driven /> 
    <!-- 支持@AspectJ标记--> 
    <aop:aspectj-autoproxy /> 
    <!--以AspectJ方式定义AOP --> 
    <tx:advice id="txAdvice" transaction-manager="transactionManager"> 
       <tx:attributes> 
        <tx:method name="get*" read-only="true" /> 
        <tx:method name="find*" read-only="true" /> 
        <tx:method name="search*" read-only="true" /> 
        <tx:method name="*" /> 
       </tx:attributes> 
    </tx:advice> 

    <!--以AspectJ方式定义AOP 第二种方法--> 

    <tx:advice id="txAdvice" transaction-manager="txManager">
    <tx:attributes>
    <tx:method name="add*" propagation="REQUIRED"/>
    <tx:method name="del*" propagation="REQUIRED"/>
    <tx:method name="update*" propagation="REQUIRED"/>
    <tx:method name="save*" propagation="REQUIRED"/>
    <tx:method name="insert*" propagation="REQUIRED"/>
    <tx:method name="*" read-only="true" />
    </tx:attributes>
    </tx:advice>


    <aop:config proxy-target-class="true"> <aop:advisor pointcut="execution(* com.ssh.idao.*DAO.*(..))" advice-ref="txAdvice" /> </aop:config> <bean name="/view" class="com.ssh.struts.action.ViewAction"> </bean> 2.与ibaitis集成,只需配置jdbc事务即可 <context:component-scan base-package="com.filmdubbing.manager"/> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="${jdbc.driverClassName}" /> <property name="url" value="${jdbc.url}" /> <property name="username" value="${jdbc.username}" /> <property name="password" value="${jdbc.password}" /> <property name="initialSize" value="5" /> <property name="maxActive" value="100" /> <property name="maxIdle" value="30" /> <property name="maxWait" value="1000" /> <property name="poolPreparedStatements" value="true" /> <property name="defaultAutoCommit" value="true" /> <property name="validationQuery" value="select 1 from dual" /> <property name="testOnBorrow" value="true" /> </bean> <bean id="yzfwTM" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource" /> </bean> <tx:advice id="yzfwTA" transaction-manager="yzfwTM"> <tx:attributes> <tx:method name="get*" propagation="REQUIRED" read-only="true" rollback-for="Throwable" /> <tx:method name="find*" propagation="REQUIRED" read-only="true" rollback-for="Throwable" /> <tx:method name="*" propagation="REQUIRED" rollback-for="Throwable" /> </tx:attributes> </tx:advice> <aop:config proxy-target-class="true"> <aop:pointcut id="yzfwTO" expression="execution(* com.filmdubbing.manager..*.*(..))" /> <aop:advisor advice-ref="yzfwTA" pointcut-ref="yzfwTO" /> </aop:config>
  • 相关阅读:
    希腊字母写法
    The ASP.NET MVC request processing line
    lambda aggregation
    UVA 10763 Foreign Exchange
    UVA 10624 Super Number
    UVA 10041 Vito's Family
    UVA 10340 All in All
    UVA 10026 Shoemaker's Problem
    HDU 3683 Gomoku
    UVA 11210 Chinese Mahjong
  • 原文地址:https://www.cnblogs.com/xunianchong/p/4921177.html
Copyright © 2020-2023  润新知