java - AspectJ Pointcut to exclude annotation -


i'm using spring aop logging. want create pointcut applies methods except have specific annotation, have no idea how go it. i've found how include methods annotation.

sample annotation:

package de.scrum_master.app;  import java.lang.annotation.retention; import java.lang.annotation.retentionpolicy;  @retention(retentionpolicy.runtime) public @interface nologging {} 

driver application:

package de.scrum_master.app;  public class application {     public static void main(string[] args) throws exception {         foo();         bar();         zot();         baz();     }      @nologging public static void foo() {}     public static void bar() {}     @nologging public static void zot() {}     public static void baz() {} } 

aspect in native aspectj syntax:

package de.scrum_master.aspect;  import de.scrum_master.app.nologging;  public aspect myaspect {     before() : execution(* *(..)) && !@annotation(nologging) {         system.out.println(thisjoinpoint);     } } 

aspect in @aspectj syntax (should work in spring aop):

package de.scrum_master.aspect;  import org.aspectj.lang.joinpoint; import org.aspectj.lang.annotation.aspect; import org.aspectj.lang.annotation.before;  @aspect public class myaspectx {     @before("execution(* *(..)) && !@annotation(de.scrum_master.app.nologging)")     public void logexceptannotated(joinpoint thisjoinpoint) throws throwable {         system.out.println(thisjoinpoint);     } } 

both aspects equivalent , yield following output:

execution(void de.scrum_master.app.application.main(string[])) execution(void de.scrum_master.app.application.bar()) execution(void de.scrum_master.app.application.baz()) 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -