Spring AOP、AspectJ、CGLIB 都是什么?它们有什么关系?

转载:https://mp.weixin.qq.com/s?__biz=MzI1MTYxNTE0Ng==&mid=2247494047&idx=1&sn=da9d49a4c3d49919c44b93f9310ddc27&chksm=e9f2eb5ade85624c14bb4c5c41907b0adb4849da340169a76634b1f07ca1625b630af2418d82&cur_album_id=1954387956761264133&scene=189&poc_token=HBDRNGWjlVdLiyoKdUy4_cHc0zI654tn6InRJFrK

在这里插入图片描述

package com.ywsc.fenfenzhong.aspectj.learn;
public class SayHelloService {
    public void say(){
        System.out.print("Hello  AspectJ");
    }
} 

在这里插入图片描述

package com.ywsc.fenfenzhong.aspectj.learn;
public aspect LogAspect{
    pointcut logPointcut():execution(void SayHelloService.say());
    after():logPointcut(){
         System.out.println("记录日志 ..."); 
    }
}

在这里插入图片描述

<aop:aspectj-autoproxy/>

在这里插入图片描述

package com.ywsc.fenfenzhong.aspectj.learn;
import org.springframework.stereotype.Component;
@Component
public class SayHelloService {
    public void say(){
        System.out.print("Hello  AspectJ");
    }
} 

在这里插入图片描述

package com.ywsc.fenfenzhong.aspectj.learn;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;
@Aspect
@Component
public class LogAspect {
     @After("execution(* com.ywsc.fenfenzhong.aspectj.learn.SayHelloService.*(..))")
     public void log(){
         System.out.println("记录日志 ...");
     }
}
package com.ywsc.fenfenzhong.mongodb;
import com.ywsc.fenfenzhong.aspectj.learn.SayHelloService;
public class TestCase {
    public static void main(String[] args) {
        SayHelloService sayHelloService = ApplicationUtil.getContext().getBean(SayHelloService.class);
        sayHelloService.say();
    }
}

在这里插入图片描述

Hello  AspectJ
记录日志...

在这里插入图片描述

<aop:aspectj-autoproxy proxy-target-class="true"/>

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值