다이나믹 프록시
JDK 다이나믹 프록시
BookService bookService = (BookService) Proxy.newProxyInstance(BookService.class.getClassLoader(), new Class[]{BookService.class},
new InvocationHandler() {
BookService bookService = new DefaultBookService();
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
if (method.getName().equals("rent")) {
System.out.println("before method call");
Object invoke = method.invoke(bookService, args);
System.out.println("after method call");
return invoke;
}
return method.invoke(bookService, args);
}
});클래스 기반 다이나믹 프록시
CGLIB
ByteBuddy
Last updated