diff --git a/pom.xml b/pom.xml index 25aad6e..fb41eef 100644 --- a/pom.xml +++ b/pom.xml @@ -16,6 +16,12 @@ 5.3.23 + + org.aspectj + aspectjweaver + 1.9.6 + + junit diff --git a/src/main/java/com/msb/proxy/springAop/v1/LogProxy.java b/src/main/java/com/msb/proxy/springAop/v1/LogProxy.java new file mode 100644 index 0000000..fd2bd55 --- /dev/null +++ b/src/main/java/com/msb/proxy/springAop/v1/LogProxy.java @@ -0,0 +1,23 @@ +package com.msb.proxy.springAop.v1;/** + * @Author bingor + * @Date 2022/10/17 14:45 + * @Description: com.msb.proxy.springAop.v1 + * @Version: 1.0 + */ + +/** + *@ClassName LogProxy + *@Description TODO + *@Author bingor + *@Date 2022/10/17 14:45 + *@Version 3.0 + */ +public class LogProxy { + public void before() { + System.out.println("method for before execute..."); + } + + public void after() { + System.out.println("method for after execute..."); + } +} diff --git a/src/main/java/com/msb/proxy/springAop/v1/Main.java b/src/main/java/com/msb/proxy/springAop/v1/Main.java new file mode 100644 index 0000000..b4828ef --- /dev/null +++ b/src/main/java/com/msb/proxy/springAop/v1/Main.java @@ -0,0 +1,24 @@ +package com.msb.proxy.springAop.v1;/** + * @Author bingor + * @Date 2022/10/17 14:54 + * @Description: com.msb.proxy.springAop.v1 + * @Version: 1.0 + */ + +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +/** + *@ClassName Main + *@Description TODO + *@Author bingor + *@Date 2022/10/17 14:54 + *@Version 3.0 + */ +public class Main { + public static void main(String[] args) { + ApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"applicationContext.xml"}); + Tank tank = (Tank) context.getBean("tank"); + tank.move(); + } +} diff --git a/src/main/java/com/msb/proxy/springAop/v1/Tank.java b/src/main/java/com/msb/proxy/springAop/v1/Tank.java new file mode 100644 index 0000000..8e33d69 --- /dev/null +++ b/src/main/java/com/msb/proxy/springAop/v1/Tank.java @@ -0,0 +1,29 @@ +package com.msb.proxy.springAop.v1;/** + * @Author bingor + * @Date 2022/10/17 9:41 + * @Description: com.msb.proxy.v5 + * @Version: 1.0 + */ + +import com.msb.proxy.cglib.LogMethodInterceptor; +import org.springframework.cglib.proxy.Enhancer; + +import java.util.Random; + +/** + *@ClassName Tank + *@Description TODO + *@Author bingor + *@Date 2022/10/17 9:41 + *@Version 3.0 + */ +public class Tank { + public void move() { + System.out.println("tank move……"); + try { + Thread.sleep(new Random().nextInt(10000)); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/java/com/msb/proxy/springAop/v2/LogProxy.java b/src/main/java/com/msb/proxy/springAop/v2/LogProxy.java new file mode 100644 index 0000000..e4ae2a1 --- /dev/null +++ b/src/main/java/com/msb/proxy/springAop/v2/LogProxy.java @@ -0,0 +1,31 @@ +package com.msb.proxy.springAop.v2;/** + * @Author bingor + * @Date 2022/10/17 14:45 + * @Description: com.msb.proxy.springAop.v1 + * @Version: 1.0 + */ + +import org.aspectj.lang.annotation.After; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Before; +import org.aspectj.lang.annotation.Pointcut; + +/** + *@ClassName LogProxy + *@Description TODO + *@Author bingor + *@Date 2022/10/17 14:45 + *@Version 3.0 + */ +@Aspect +public class LogProxy { + @Before("execution(void com.msb.proxy.springAop.v2.Tank.move())") + public void before() { + System.out.println("auto:method for before execute..."); + } + + @After("execution(void com.msb.proxy.springAop.v2.Tank.move())") + public void after() { + System.out.println("auto:method for after execute..."); + } +} diff --git a/src/main/java/com/msb/proxy/springAop/v2/Main.java b/src/main/java/com/msb/proxy/springAop/v2/Main.java new file mode 100644 index 0000000..4c6af61 --- /dev/null +++ b/src/main/java/com/msb/proxy/springAop/v2/Main.java @@ -0,0 +1,24 @@ +package com.msb.proxy.springAop.v2;/** + * @Author bingor + * @Date 2022/10/17 14:54 + * @Description: com.msb.proxy.springAop.v1 + * @Version: 1.0 + */ + +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +/** + *@ClassName Main + *@Description TODO + *@Author bingor + *@Date 2022/10/17 14:54 + *@Version 3.0 + */ +public class Main { + public static void main(String[] args) { + ApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"application-auto.xml"}); + Tank tank = (Tank) context.getBean("tank"); + tank.move(); + } +} diff --git a/src/main/java/com/msb/proxy/springAop/v2/Tank.java b/src/main/java/com/msb/proxy/springAop/v2/Tank.java new file mode 100644 index 0000000..ab9b641 --- /dev/null +++ b/src/main/java/com/msb/proxy/springAop/v2/Tank.java @@ -0,0 +1,26 @@ +package com.msb.proxy.springAop.v2;/** + * @Author bingor + * @Date 2022/10/17 9:41 + * @Description: com.msb.proxy.v5 + * @Version: 1.0 + */ + +import java.util.Random; + +/** + *@ClassName Tank + *@Description TODO + *@Author bingor + *@Date 2022/10/17 9:41 + *@Version 3.0 + */ +public class Tank { + public void move() { + System.out.println("auto: tank move……"); + try { + Thread.sleep(new Random().nextInt(10000)); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/resources/application-auto.xml b/src/main/resources/application-auto.xml new file mode 100644 index 0000000..9dc1ca5 --- /dev/null +++ b/src/main/resources/application-auto.xml @@ -0,0 +1,11 @@ + + + + + + + \ No newline at end of file diff --git a/src/main/resources/applicationContext.xml b/src/main/resources/applicationContext.xml index f94c065..f4ef295 100644 --- a/src/main/resources/applicationContext.xml +++ b/src/main/resources/applicationContext.xml @@ -1,7 +1,22 @@ + xmlns:aop="http://www.springframework.org/schema/aop" + xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd + http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd"> + + + + + + + + + + + + + \ No newline at end of file