Voglio creare un log di annotazione personalizzate nel mio progetto Grails.AOP con Grails
Il mio codice:
class MyService{
@AuditLog
def method1() {
println "method1 called"
method2()
}
@AuditLog
def method2() {
println "method2 called"
}
}
Interceptor:
class AuditLogInterceptor implements MethodInterceptor {
@Override
Object invoke(MethodInvocation methodInvocation) throws Throwable {
println "${methodInvocation.method}"
return methodInvocation.proceed();
}
}
Primavera config:
aop {
config("proxy-target-class": true) {
pointcut(id: "auditLogInterceptorPointcut", expression: "@annotation(xxx.log.AuditLog)")
advisor('pointcut-ref': "auditLogInterceptorPointcut", 'advice-ref': "auditLogInterceptor")
}
}
auditLogInterceptor(AuditLogInterceptor) {}
Il risultato:
public java.lang.Object xxx.MyService.method1()
method1 called
method2 called
Vorrei vedere il fuoco di annotazione per il metodo 2 pure. Cosa mi manca?
Bella intuizione! Penso che sarebbe bello se Grails fornisce qualche magia di delegare le chiamate ai metodi nella stessa classe di servizio alla classe proxy. –