Advice源码分析

master
linlei 2024-04-07 15:45:12 +08:00
parent 11db48f583
commit 2a141eb5e6
2 changed files with 25 additions and 2 deletions

View File

@ -3,16 +3,23 @@ package com.xcs.spring;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aop.support.DefaultIntroductionAdvisor;
/**
* @author xcs
* @date 20244715:42:49
*/
public class AdviceDemo {
public static void main(String[] args) {
// methodInterceptor();
methodInterceptor();
// beforeAdvice();
// afterAdvice();
// throwsAdvice();
introductionAdvice();
// introductionAdvice();
}
/**
*
*/
private static void methodInterceptor() {
// 创建代理工厂&创建目标对象
ProxyFactory proxyFactory = new ProxyFactory(new MyService());
@ -24,6 +31,9 @@ public class AdviceDemo {
proxy.doSomething();
}
/**
*
*/
private static void beforeAdvice() {
// 创建代理工厂&创建目标对象
ProxyFactory proxyFactory = new ProxyFactory(new MyService());
@ -35,6 +45,9 @@ public class AdviceDemo {
proxy.doSomething();
}
/**
*
*/
private static void afterAdvice() {
// 创建代理工厂&创建目标对象
ProxyFactory proxyFactory = new ProxyFactory(new MyService());
@ -46,6 +59,9 @@ public class AdviceDemo {
proxy.doSomething();
}
/**
*
*/
private static void throwsAdvice() {
// 创建代理工厂&创建目标对象
ProxyFactory proxyFactory = new ProxyFactory(new MyService());
@ -57,6 +73,9 @@ public class AdviceDemo {
proxy.doSomethingException();
}
/**
*
*/
private static void introductionAdvice() {
// 创建代理工厂&创建目标对象
ProxyFactory proxyFactory = new ProxyFactory(new MyService());

View File

@ -6,6 +6,10 @@ import org.springframework.aop.support.DefaultPointcutAdvisor;
import org.springframework.aop.support.NameMatchMethodPointcut;
import org.springframework.aop.support.annotation.AnnotationMatchingPointcut;
/**
* @author xcs
* @date 20244715:42:49
*/
public class PointcutDemo {
public static void main(String[] args) {
customPointcut();