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();
}
}
봄 설정 :
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가 동일한 서비스 클래스에있는 메소드에 대한 호출을 프록시 클래스에 위임 할 수있는 마법을 제공하면 좋을 것 같습니다. –