Descripción
Create a dynamic proxy for an interface with logging before and after method execution
File Template: ❌
Prefix
proxy:dynamic
Scopes
java
Snippet de código
${1:ServiceInterface} service = ($1) Proxy.newProxyInstance(
$1.class.getClassLoader(),
new Class[]{ $1.class },
new InvocationHandler() {
private final ${2:Service} real = new $2();
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
System.out.println("Before executing method: " + method.getName());
Object result = method.invoke(real, args);
System.out.println("After executing method: " + method.getName());
return result;
}
}
);