AspectJ expression gives formal unbound in pointcut error

断了今生、忘了曾经 提交于 2019-12-12 08:22:49

问题


I have within aspectJ the expression:

@Pointcut("within(com.param.cpms.dao.impl.ProjectMetaDaoImpl)")
public void daoExceptionHandle() {

}

At Spring 3.0 startup, I am getting the following error :

nested exception is java.lang.IllegalArgumentException: error at ::0 formal unbound in pointcut

回答1:


Probably the problem is not in your pointcut, but in an advice using that pointcut and using a parameter which does not exist in the pointcut. Just remove the parameter from the advice (well, or add it to the pointcut).




回答2:


The post is rather old, but for the sake of completeness I am adding another reason, if you use @Around advice.

According to Spring AspectJ documentation the advice's first argument must be ProceedingJoinPoint. If it's missing, you will get exactly this exception message. Sadly, the exception does not point to advice in error so solving the bug is a hit-and-miss.




回答3:


I got this error because of wrong import of class. I should have imported import org.aspectj.lang.JoinPoint class , but instead imported some other Joinpoint class from a different package.




回答4:


It was Joinpoint ("p lowercase)

org.aopalliance.intercept.Joinpoint;

Change to JointPoint("P uppercase)

org.aspectj.lang.JoinPoint; 



回答5:


I also had this problem, and in my case it was a wrong import from: org.aopalliance.intercept.Joinpoint;

It needs to be: org.aspectj.lang.JoinPoint;




回答6:


Sometimes the reason could be this.

 public void afterReturning(JoinPoint joinPoint, Object result)

Just remove Object result as below and it works for me.

public void afterReturning(JoinPoint joinPoint)



回答7:


If you are using XML based configuration and if your configuration is something like this :

<aop:config>
<aop:aspect ref="bAdvice">
    <aop:pointcut id="displayPointcut" expression="execution(* com.example.demo.BusinessClass.display())"/>
    <aop:before method="before" pointcut-ref="displayPointcut" />
</aop:aspect>
</aop:config>

Then in 2 scenarios, you are getting the error :

  1. If in pointcut expression, method i.e. display() in our case have defined without any parameters and in the actual class method have some parameters.
  2. If in before advice i.e. aop:before, method="before" have defined without arg-names and in actual advice class, the method "before" have some parameters.

Ultimately when method parameters defined in XML mismatched with actual method, then this error will come.




回答8:


This is not you answer but may be it will help you a little.

Spring AOP Tutorial you can refer this tutorial

@Before("execution(* com.de.controller..*(..))")
public void beforeLoggerAdvice(JoinPoint joinPoint, WebRequest request) {
    DeUtil.looger.info("--working");
}

I got the same Exception but because of WebRequest, i removed that and using the alternative

HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest();



回答9:


The formal unbound in pointcut exception also occurs for two resons in AOP.

Reason 1: If there are no return statement in after returning advice

For XML based implementation

<aop:aspect id="myaspect" ref="trackAspect">
<aop:pointcut id="pointCutAfterReturning" expression="execution(* com.springlearn.Operation.*(..))" />
<aop:after-returning method="myAdvice"  returning="result" pointcut-ref="pointCutAfterReturning"/>  //Make sure returning result is added
</aop:aspect>

For Annotation based implementation

@AfterReturning(  
              pointcut = "execution(* Operation.*(..))",  
              returning= "result") //Make sure returning result is added

Reason 2: If there is no throwing in After throwing Advice

For XML based implementation

<aop:aspect id="myaspect" ref="trackAspect" >  
     <!-- @AfterThrowing -->  
     <aop:pointcut id="pointCutAfterThrowing"    expression="execution(* com.javatpoint.Operation.*(..))" />  
     <aop:after-throwing method="myadvice" throwing="error" pointcut-ref="pointCutAfterThrowing" />  //Make sure throwing error is added
  </aop:aspect> 

For Annotation based Implementation

@AfterThrowing(  
              pointcut = "execution(* Operation.*(..))",  
              throwing= "error")  //Make sure throwing error is added



回答10:


I was getting the same error, in my scenario I was using two method parameters

public void methodName(JoinPoint joinPoint ,HttpServletRequest request) throws

and my annotation was like

@Before("execution(public * com.java.controller.*Controller.*(..))")

As a solution I have added

args(request,..)

@Before("execution(public * com.java.controller.*Controller.*(..)) && args(request,..)")


来源:https://stackoverflow.com/questions/12258150/aspectj-expression-gives-formal-unbound-in-pointcut-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!