5
मैं अपने Grails प्रोजेक्ट में एक कस्टम लॉगिंग एनोटेशन बनाना चाहता हूं।Grails के साथ AOP
मेरे कोड:
class MyService{
@AuditLog
def method1() {
println "method1 called"
method2()
}
@AuditLog
def method2() {
println "method2 called"
}
}
इंटरसेप्टर:
class AuditLogInterceptor implements MethodInterceptor {
@Override
Object invoke(MethodInvocation methodInvocation) throws Throwable {
println "${methodInvocation.method}"
return methodInvocation.proceed();
}
}
स्प्रिंग config:
aop {
config("proxy-target-class": true) {
pointcut(id: "auditLogInterceptorPointcut", expression: "@annotation(xxx.log.AuditLog)")
advisor('pointcut-ref': "auditLogInterceptorPointcut", 'advice-ref': "auditLogInterceptor")
}
}
auditLogInterceptor(AuditLogInterceptor) {}
परिणाम:
public java.lang.Object xxx.MyService.method1()
method1 called
method2 called
मैं विधि 2 के लिए एनोटेशन आग भी देखना चाहता हूं। मैं क्या खो रहा हूँ?
अच्छी अंतर्दृष्टि! मुझे लगता है कि यह बहुत अच्छा होगा अगर Grails प्रॉक्सी कक्षा में एक ही सेवा कक्षा में विधियों को कॉल करने के लिए कुछ जादू प्रदान करता है। –