package customutil.proxy.dynamicProxy; import net.sf.cglib.proxy.Enhancer; import net.sf.cglib.proxy.MethodInterceptor; import net.sf.cglib.proxy.MethodProxy; import java.lang.reflect.Method; /** * @author EBU7-dev1-ayh * @create 2021/11/25 0025 13:06 */ public class TestCGLIB { public static void main(String[] args) { Customer customer = new Customer(); Customer deliveryClerk = (Customer) Enhancer.create(Customer.class, new MethodInterceptor() { @Override public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable { Object result = method.invoke(customer,objects); System.out.println("接收到订单,正在去取餐途中。。。"); return result; } }); String result = deliveryClerk.order("口水鸡"); System.out.println(result); } }