Results 1 to 3 of 3

Thread: How Define PointCut for annotation on Interface ?

Hybrid View

  1. #1
    Join Date
    Apr 2011
    Posts
    10

    Default 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. #2
    Join Date
    Jul 2010
    Posts
    139

    Default

    Have you tried:

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

  3. #3
    Join Date
    Apr 2011
    Posts
    10

    Default

    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...

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •