Spring-Mybatis整合配置文件与AOP织入方式对比

对比AOP织入 方式一


    
    

        

            

            
            
        
        
    

 对比AOP织入 方式二




    
    
    
 


   

       

       
       
 
   
 

 注解实现AOP

package com.qf.common;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

//增强类  事务管理类
//切面=切点加通知
@Aspect
@Component
public class TransManger {
    //定义切点,无参无返回值的方法  pc相当于切点的ID
    @Pointcut("execution(* com.qf.service..*.*(..))")
    public void pc(){}

    @Before("pc()")
    public  void startTran(){
        System.out.println("开启事务~~~~~~~~~~~~");
    }

    @AfterReturning("pc()")
    public void commitTran(){
        System.out.println("提交事务.............");
    }
   @AfterThrowing("pc()")
     public void rollBackTran(){
         System.out.println("回滚事务~~~~~~~~~~~~~~");
     }
@After("pc()")
     public void afterMethod(){
         System.out.println("测试AOP");
     }

//     加给AOP:around环绕通知
    @Around("pc()")
    public Object aroundMethod(ProceedingJoinPoint pj) throws Throwable {
        System.out.println("环绕执行前");
        long start = System.currentTimeMillis();
        Object proceed = pj.proceed();
        long end = System.currentTimeMillis();
        System.out.println(".......delete_after");
        System.out.println(end-start);
        System.out.println("环绕执行后");
        return proceed;
    }

}

spring-dao.xml 



    
    

    
    

    
    
        
        
        
        
    
    
    
        
        
        
        
        
        
        
        

    

    
    
    
        
        

        
        
    

    
    
        
        

    



    
        
            
            
        
    

    
        
        
    



导入的依赖



    4.0.0

    com.qf
    Spring-Mybatis
    1.0-SNAPSHOT

    
        8
        8
        5.3.20
    

    
        
            mysql
            mysql-connector-java
            5.1.47
        
        
            org.mybatis
            mybatis
            3.5.6
        
        
        
            org.springframework
            spring-jdbc
            ${spring-version}
        
        
        
            org.springframework
            spring-context
            ${spring-version}
        
        
        
            org.springframework
            spring-aspects
            ${spring-version}
        
        
            org.springframework
            spring-test
            ${spring-version}
        
        
            org.mybatis
            mybatis-spring
            1.3.1
        

        
            com.alibaba
            druid
            1.2.8
        
        
            org.projectlombok
            lombok
            1.18.26
        
        
            junit
            junit
            4.12
            test
        
    

你可能感兴趣的:(Spring,mybatis,spring,java)