Announcement Announcement Module
Collapse
No announcement yet.
Trouble with @annotation :0 formal unbound in pointcut Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Trouble with @annotation :0 formal unbound in pointcut

    Im trying to introduce pre validation inside my service classes with aspects.
    For this i have created an annotation for validation
    Code:
    package com.example.services;
    .....
    @Retention(RetentionPolicy.RUNTIME)
    @Target(ElementType.METHOD)
    public @interface Validatable {
    	public String key();
    	public Class[] validators();
    }
    The idea was to intercept all methods inside the service layer if they have been marked with a validatable annotation.
    I have a system architecture aspect which looks like this
    Code:
    @Aspect
    public class SystemArchitectureAspect {
    
    	@Pointcut("within(com.example.*.services..*)")
    	public void inServicesLayer(){}
    
    	@Pointcut("within(com.example.*.dao..*)")
    	public void inDaoLayer(){}
    	
    	@Pointcut("within(com.example.*.rules..*)")
    	public void inRulesLayer(){}
    	
    	@Pointcut("execution(* com.example.*.services.*.*(..))")
    	public void subServiceLayer(){}
    
    }
    Aspect for validation as
    Code:
    @Aspect
    public class ServiceValidationAspect {
    	@Pointcut("com.example.aspects.SystemArchitectureAspect.inServicesLayer() " +
    			"&& com.example.aspects.SystemArchitectureAspect.subServiceLayer()")	
              public void doServicePrevalidation(){}
               }
    	@Around("com.example.aspects.ServiceValidationAspect.doServicePrevalidation() "+
    	" && @annotation(com.example.services.Validatable) ")
    	public void validate(ProceedingJoinPoint pjp,AliseServicePrevalidate va){
    ......
         }
    }
    The idea was to inspect the annotation at runtime to find the validator classes. But I am not able to get the around aspect going . It always throws me an illegal argument exception with 0 formals bound.

    Im using spring-aop 2.5.3 and aspectj version 1.5.3 vers. By spring documentation this is possible
    Code:
    @Before("com.xyz.lib.Pointcuts.anyPublicMethod() && " + 
            "@annotation(auditable)")
    public void audit(Auditable auditable) {
      AuditCode code = auditable.value();
      // ...
    }
    Can anyone tell me where im going wrong? or did i get the concept all together wrong?

  • #2
    public void validate(ProceedingJoinPoint pjp,AliseServicePrevalidate va)

    What is va?

    In your advice declaration you don't appear to be binding the parameter 'va' - the pointcut must bind it to state where the value for it comes from when the advice is invoked.

    Andy Clement
    AspectJ Project Lead
    SpringSource

    Comment


    • #3
      thanks Andy for the quick reply..It works perfectly
      Apologies for the haste of the posting (late hours i guess)

      Do you think it is a good idea to keep validation as an aspect?

      Comment

      Working...
      X