Announcement Announcement Module
Collapse
No announcement yet.
@Before not working with arguments Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • @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
    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

    Comment


    • #3
      My bad


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


      should be

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

      Comment

      Working...
      X