• sping中注解事务的应用


    1.spring配置文件中配置

    	<aop:config>
    		<aop:pointcut id="appService" expression="execution(* com.hhr.service.*Service*.*(..))" />
    		<aop:advisor advice-ref="txAdvice" pointcut-ref="appService" />
    	</aop:config>
    
    	<tx:advice id="txAdvice" transaction-manager="transactionManager">
    		<tx:attributes>
    			<tx:method name="select*" read-only="true" />
    			<tx:method name="find*" read-only="true" />
    			<tx:method name="get*" read-only="true" />
    			<tx:method name="*" />
    		</tx:attributes>
    	</tx:advice>
    
    	<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    		<property name="dataSource" ref="dataSource" />
    	</bean>
    	
    	<tx:annotation-driven transaction-manager="transactionManager" />
    

    2.调用

    @Transactional(rollbackFor=Exception.class)
    public void test(){
         update(obj)
          throw new Exception();
    }
    

     其中 1)test方法中不能加try catch语句

       2)数据库表为innodb

        

      

  • 相关阅读:
    C#
    C#
    css
    css
    css
    css
    css
    Css
    Javascript
    ASP.NET MVC
  • 原文地址:https://www.cnblogs.com/wonder2636/p/5531175.html
Copyright © 2020-2023  润新知