I need to handle all the exceptions that are thrown from public methods of class annotated with some annotation. I trying to use Spring AOP. This is my logger:
@Aspect
public class Logger {
private final Logger log = LoggerFactory.getLogger(this.getClass());
@Pointcut("@annotation(loggable)")
public void isLoggable(Loggable loggable) {
}
@AfterThrowing(pointcut = "isLoggable(loggable)", throwing = "e")
public void afterThrowing(Loggable loggable, Exception e) throws Throwable {
log.error("AFTER", e);
}
@Loggable
is my annotation.
Then I've added @EnableAspectJAutoProxy
annotation to my configuration class.
First I've tried to annotate some method that throws an exception. It works fine but how can I make this work for all public methods in class annotated with @Loggable
annotation?