Announcement Announcement Module
Collapse
No announcement yet.
How Define PointCut for annotation on Interface ? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How Define PointCut for annotation on Interface ?

    Hi,

    I try to run an aspect when the method of class implementation is call if the interface of this class have an annotation...
    With an example it's easier:

    I have the interface with on annotation @Cacheable:
    Code:
    public interface AccountService {	
    		
    	@Cacheable
    	public List<AccountDTO> getAccounts();	
    }
    And I have also an implementation of this interface

    Code:
    @Service
    public class AccountServiceImpl implements AccountService{
    
    	public List<AccountDTO> getAccounts() {
    	...
    	}
    }
    And also an Advice :

    Code:
    @Component
    @Aspect
    public class MyAdvice {
    		
    	@Pointcut("@within(Cacheable) || @Annotation(Cacheable)) 
    	public static void addCachePointcut(){};
    	
    	@Around("addControlPointcut()")	
    	public Object addCache(ProceedingJoinPoint point) throws Throwable{
    	  ...	
    	}
    This code works fine if the annotation is on the method of the AccountServiceImpl class, but do nothing if the annotation is on AccountService.
    I read Spring documentation about other Pointcut tools, but I found nothing to run this Advice.
    I miss something?

    Thanks for your help

  • #2
    Have you tried:

    Code:
    @target(your.package.here.Cacheable)

    Comment


    • #3
      Thanks for your answer.
      But yes I try again with @target, but it's not works.
      In my sample, @target and @within do the same thing, and Aspect is run only if the @Cacheable is define on the AccountServiceImpl class.

      Notice than I get an error with @target pointcut in spring-aop-3.0.5.RELEASE.jar, and not in spring-aop-2.5.6.jar. It's seems it is a bug...

      Comment

      Working...
      X