Results 1 to 3 of 3

Thread: @Before not working with arguments

  1. #1

    Default @Before not working with arguments

    I have created a Aspect EmployeeAspect.aj



    @Aspect
    public aspect EmployeeAspect {


    @Before("execution(* com.employee.domain.*.persist(..))")
    public void doIDcheck(){
    System.out.println("Called before Persist");
    }

    @Before("execution(* com.employee.domain.*.persist())&& args(entity)")
    public void doIDcheck(EmployeeEntity entity){
    System.out.println("Called before Persist with entity");
    }
    }

    The method doIDcheck is called when I call enity .persist() It works for the doIDcheck with no arguments. But is not called with arguments added.

    Thanks for any help,

  2. #2

    Default

    I think I got my understanding wrong, it wont call persist since persist does not take any arguments. I have a method setEmployee which takes a employee as an argument.

    so I added the following method to my aspect


    @Before("execution(* com.employee.service.*.setEmployee())&& args(emp)")
    public void doIDcheck(Employee emp){
    System.out.println("Called before setEmployee");
    }

    Which still does not work.

    Thanks for any help

  3. #3

    Default

    My bad


    @Before("execution(* com.employee.service.*.setEmployee())&& args(emp)")


    should be

    @Before("execution(* com.employee.service.*.setEmployee(..))&& args(emp)")

Posting Permissions

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