The following is my pointcut and advise declaration
//PointCut on A method which takes two parameters and is in a DAO
@Pointcut("execution(backend.repository.QuestionsRepository.AnswerQuestion (..))")
public void answerQuestionPointCut() {}
@Around(
value="web.activity.advisors.UserActivityAdvisor.answerQuestionPointCut()",
argNames="question,answer"
)
// Do something
}
I get the following error
Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: Pointcut is not well-formed: expecting 'name pattern' at character position 65
execution(backend.repository.QuestionsRepository.AnswerQuestion (..))
^
Am stuck on this, Any pointers
You are missing the return type:
and you have to bind the argument names, something like this:
Example Solution
Service Interface:
Implementation class:
Spring AOP aspect:
Spring Context XML:
Main class for testing:
Now here’s a main method to test the whole process. It starts a Spring ApplicationContext
without XML configurationwith the above XML defining the service bean and the aspect (it turns out that the solution without XML only worked because I had AspectJ weaving turned on, I don’t know what beans I have to include to enable aspectj-autoproxy, so I now useClassPathXmlApplicationContextwith this minimal XML):Output:
This should get you started. Basically: you need to check that the methods you are intercepting are backed by a service interface if you use JDK proxies (spring default). Read here about Spring AOP proxy mechanisms.
Note:
As you see I bind the method arguments to the aspect, not the pointcut, hence making the pointcut reusable for methods with different argument signatures. But it would also be possible to bind them in the pointcut, like this: