java - Spring AOP: create pointcut which check parent class annotation -


i have next interface , implementation:

@step public interface testaopcomp {     void test(); }  @component public class testaopcompimpl implements testaopcomp{     public void test(){         system.out.println("test");     } } 

i need intercept execution of methods of classes, extends classes annotation @step. please me write pointcut.

for example use next pointcut intercept methods of classes, annotated @step:

@pointcut("@within(step)") 

but not work, if annotate super class

i investigate problem. if use extends class (it may abstract) , annotation announce inherited pointcut work, not work implemented interfaces.

next example work, not work annotations on implemented interfaces:

@step public abstract class testaopcomp {     public abstract void test(); }  @component public class testaopcompimpl extends testaopcomp{     public void test(){         system.out.println("test");     } }  @inherited @retention(retentionpolicy.runtime) @target(elementtype.type) public @interface step { }  @component @aspect public class aspect {     @pointcut("@within(step)")     public void stepclass(){}      @around("stepclass()")     public void steparound(proceedingjoinpoint pjp){         system.out.println("before");         try {             pjp.proceed(pjp.getargs());         } catch (throwable throwable) {             throwable.printstacktrace();         }         system.out.println("after");     } } 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -