I'm newbie to Spring AOP.
I've written aspect advice for all methods in my application while it throws exception.(I've tried it with grails.)
ExceptionService.groovy
@Aspect
public class ExceptionService {
def logMessage(def message){
def expInstance = new LogMessage(message:message)
expInstance.save(flush:true)
}
@Pointcut("execution(* com.mypackage..* (..))")
def allActions(){}
@AfterThrowing(pointcut="allActions()", throwing="e")
def allActionAdvice(JoinPoint joinPoint, Throwable e){
def className = joinPoint.getTarget().getClass().getSimpleName()
logMessage(className+"\n"+e.message)
}
@Pointcut("execution(* org.apache.commons.logging.Log.error(..))")
def logErrorActions(){}
@Before(value = "logErrorActions()")
def logErrorActionAdvice(JoinPoint joinPoint){
def className = joinPoint.getTarget().getClass().getSimpleName()
logMessage("Error in "+className)
}
}
resources.groovy
beans = {
xmlns aop:"http://www.springframework.org/schema/aop"
aspectBean(com.mypackage.services.ExceptionService)
aop.config("proxy-target-class":true) {
}
}
Here, it's working fine for all exceptions allActionAdvice()
which occurs inside application. But it's not working for log.error(logErrorActionAdvice())
.
I researched for it on Google and it tells that the issue is with AOP and third party dependency like weaving. So, I need to do aspect weaving (compile time weaving). But I don't found any good example.
What do I need to change about my Grails application to use compile time weaving of my aspect or is there something else that I need to do?