up vote 1 down vote favorite

I'm new with AspectJ and I try to do this:

This is my current Code.

public class MyDBDAO {
    public boolean update(MyObject myObject) {}
}

And Aspect:

@Aspect
@Component
public class AspectJClass {
   @Pointcut("execution(* com.myclass.MyDBDAO.update()) && args(myObject)")
    public void update(MyObject myObject) {}
 }

Should I only use absoulute Type? Are there any ways to solve this problem?

java spring aspectj args pointcut share | improve this question asked Feb 17 '16 at 13:23 ellen 8 3      What exactly are you trying to do? –  Austin D Feb 17 '16 at 14:07      I wanna validate the parameter in the aspect class before inserting DB. –  ellen Feb 18 '16 at 1:58 add a comment  | 

1 Answer 1

active oldest votes up vote 0 down vote accepted

have you tried this ?

@Pointcut("execution(void com.myclass.MyDBDAO.update(MyObject)) && args(myObject)")
public void update(MyObject myObject) {}

if you want poincut to all of the methods in the class you can do this :

@Pointcut("this(com.myclass.MyDBDAO)")
public void isMyDBDAO() {}
share | improve this answer answered Feb 17 '16 at 13:49 Yair Harel 161 1 8      Thnanks for answer! I tried the first one. But I got this message. Caused by: java.lang.IllegalArgumentException: warning no match for this type name: MyObject [Xlint:invalidAbsoluteTypeName] at org.aspectj.weaver.tools.PointcutParser.parsePointcutExpress‌​ion(PointcutParser.j‌​ava:301) at org.springframework.aop.aspectj.AspectJExpressionPointcut.bu‌​ildPointcutExpressio‌​n(AspectJExpressionP‌​ointcut.java:195) at –  ellen Feb 17 '16 at 13:59      can you post your advice code ? –  Yair Harel Feb 17 '16 at 18:18      I have just closely re-read your exception and you need to specify the full path of the class MyObject for example com.myclass.MyObject inside the pointcut. you didn't post your advice but note that an advice that advices this pointcut must also have MyObject as parameter –  Yair Harel Feb 17 '16 at 20:37      Thanks!! I finally solved the problem. I wrote pointcut like this. @Pointcut("execution(void com.myclass.MyDBDAO.update(com.model.MyObject)) && args(myObject)") public void update(MyObject myObject) {} –  ellen Feb 18 '16 at 1:59 add a comment  | 

Your Answer

  draft saved draft discarded

Sign up or log in

Sign up using Google

Sign up using Facebook

Sign up using Email and Password

Post as a guest

Name Email

Post as a guest

Name Email discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged java spring aspectj args pointcut or ask your own question.

快照源:http://blog.chinaunix.net/uid-20672803-id-3049747.html