5
Grails projemde özel bir günlük ek açıklaması oluşturmak istiyorum.AOP with Grails
Kodum:
class MyService{
@AuditLog
def method1() {
println "method1 called"
method2()
}
@AuditLog
def method2() {
println "method2 called"
}
}
keseni:
class AuditLogInterceptor implements MethodInterceptor {
@Override
Object invoke(MethodInvocation methodInvocation) throws Throwable {
println "${methodInvocation.method}"
return methodInvocation.proceed();
}
}
Bahar yapılandırma:
aop {
config("proxy-target-class": true) {
pointcut(id: "auditLogInterceptorPointcut", expression: "@annotation(xxx.log.AuditLog)")
advisor('pointcut-ref': "auditLogInterceptorPointcut", 'advice-ref': "auditLogInterceptor")
}
}
auditLogInterceptor(AuditLogInterceptor) {}
sonucu:
public java.lang.Object xxx.MyService.method1()
method1 called
method2 called
Ayrıca, yöntem 2 için ek açıklama ateşini görmek istiyorum. Neyi kaçırıyorum?
Nice insight! Grails, proxy sınıfına aynı hizmet sınıfındaki yöntemlere çağrıları devretmek için biraz sihir sağlarsa harika olur. –