spring---配置事物


两种方式

  声明式事物:aop

  编程式事物:就是在代码中手动添加事物

声明式事物

只需要在spring-dao.xml配置即可(注意需要假如相关约束)

<?xml version="1.0" encoding="UTF-8"?>
"http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/tx
       http://www.springframework.org/schema/tx/spring-tx.xsd
       http://www.springframework.org/schema/aop
       http://www.springframework.org/schema/aop/spring-aop.xsd">


    "classpath:jdbcConfig.properties" system-properties-mode="FALLBACK">
    
    "dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        "driverClassName" value="${jdbc.driver}">
        "url" value="${jdbc.url}">
        "username" value="${jdbc.username}"/>
        "password" value="${jdbc.password}">
    

    
    "sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        "dataSource" ref="dataSource">
        
        "configLocation" value="classpath:mybatis-config.xml">
        
        "mapperLocations" value="classpath:com/kuang/mapper/*.xml">
    


    
    "sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
        
        "0" ref="sqlSessionFactory">
    



    "transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        "dataSource" ref="dataSource">
    


    "txAdvice" transaction-manager="transactionManager">
        

            "addUser" propagation="REQUIRED"/>
            "selectUser" read-only="true"/>
            "deleteUser" propagation="REQUIRED"/>

        
    

    

        "txPointCut" expression="execution(* com.kuang.mapper.*.*(..))"/>

        ref="txAdvice" pointcut-ref="txPointCut">
    

.....