diff --git a/src/main/java/com/msb/proxy/cglib/LogMethodInterceptor.java b/src/main/java/com/msb/proxy/cglib/LogMethodInterceptor.java new file mode 100644 index 0000000..7174108 --- /dev/null +++ b/src/main/java/com/msb/proxy/cglib/LogMethodInterceptor.java @@ -0,0 +1,28 @@ +package com.msb.proxy.cglib;/** + * @Author bingor + * @Date 2022/10/17 14:16 + * @Description: com.msb.proxy.cglib + * @Version: 1.0 + */ + +import org.springframework.cglib.proxy.MethodInterceptor; +import org.springframework.cglib.proxy.MethodProxy; + +import java.lang.reflect.Method; + +/** + *@ClassName LogMethodInterceptor + *@Description TODO + *@Author bingor + *@Date 2022/10/17 14:16 + *@Version 3.0 + */ +public class LogMethodInterceptor implements MethodInterceptor { + @Override + public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable { + System.out.println("method execute start..."); + Object result = methodProxy.invokeSuper(o, objects); + System.out.println("method execute end..."); + return result; + } +} diff --git a/src/main/java/com/msb/proxy/cglib/Tank.java b/src/main/java/com/msb/proxy/cglib/Tank.java new file mode 100644 index 0000000..9af6881 --- /dev/null +++ b/src/main/java/com/msb/proxy/cglib/Tank.java @@ -0,0 +1,36 @@ +package com.msb.proxy.cglib;/** + * @Author bingor + * @Date 2022/10/17 9:41 + * @Description: com.msb.proxy.v5 + * @Version: 1.0 + */ + +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(); + } + } + + public static void main(String[] args) { + Enhancer enhancer = new Enhancer(); + enhancer.setSuperclass(Tank.class); + enhancer.setCallback(new LogMethodInterceptor()); + Tank tank = (Tank) enhancer.create(); + tank.move(); + } +} diff --git a/src/main/java/com/msb/proxy/v8/LogHandler.java b/src/main/java/com/msb/proxy/jdk/LogHandler.java similarity index 96% rename from src/main/java/com/msb/proxy/v8/LogHandler.java rename to src/main/java/com/msb/proxy/jdk/LogHandler.java index c6adf9a..066943f 100644 --- a/src/main/java/com/msb/proxy/v8/LogHandler.java +++ b/src/main/java/com/msb/proxy/jdk/LogHandler.java @@ -1,4 +1,4 @@ -package com.msb.proxy.v8;/** +package com.msb.proxy.jdk;/** * @Author bingor * @Date 2022/10/17 10:30 * @Description: com.msb.proxy.v8 diff --git a/src/main/java/com/msb/proxy/v8/Movable.java b/src/main/java/com/msb/proxy/jdk/Movable.java similarity index 85% rename from src/main/java/com/msb/proxy/v8/Movable.java rename to src/main/java/com/msb/proxy/jdk/Movable.java index 970f3ef..9f542c1 100644 --- a/src/main/java/com/msb/proxy/v8/Movable.java +++ b/src/main/java/com/msb/proxy/jdk/Movable.java @@ -1,4 +1,4 @@ -package com.msb.proxy.v8; +package com.msb.proxy.jdk; /** * @Author bingor diff --git a/src/main/java/com/msb/proxy/v8/Tank.java b/src/main/java/com/msb/proxy/jdk/Tank.java similarity index 97% rename from src/main/java/com/msb/proxy/v8/Tank.java rename to src/main/java/com/msb/proxy/jdk/Tank.java index 0123e86..fcc6238 100644 --- a/src/main/java/com/msb/proxy/v8/Tank.java +++ b/src/main/java/com/msb/proxy/jdk/Tank.java @@ -1,4 +1,4 @@ -package com.msb.proxy.v8;/** +package com.msb.proxy.jdk;/** * @Author bingor * @Date 2022/10/17 9:41 * @Description: com.msb.proxy.v5