26

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
cb4
  • 6,689
  • 7
  • 45
  • 57
param
  • 261
  • 1
  • 3
  • 3

10 Answers10

30

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).

kriegaex
  • 63,017
  • 15
  • 111
  • 202
  • How to add parameters ? – The Java Guy Mar 11 '16 at 01:19
  • Seriously: You cannot ask this question without providing any context. What do you want to do with the advice parameter? What do you want to bind to the unbound variable?. Depending on the answer you would use `this()`, `target()`, `args()`, `@annotation()` or something else. P.S.: I am not a medium - a mentalist maybe, but that is a different topic. ;-) – kriegaex Mar 11 '16 at 07:54
17

It was Joinpoint ("p lowercase)

org.aopalliance.intercept.Joinpoint;

Change to JointPoint("P uppercase)

org.aspectj.lang.JoinPoint; 
Dapper Dan
  • 932
  • 11
  • 23
11

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.

vacant78
  • 163
  • 1
  • 7
  • Thanks for sharing this! It was exactly the problem in my case. I implemented `MethodInterceptor` and put the `@Around` annotation on its `invoke` method. But now I know, `@Around` is not made for `MethodInterceptor.invoke`. – Ethan Leroy Sep 07 '18 at 06:57
5

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.

Anshu Pandey
  • 49
  • 1
  • 4
3

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,..)")
Urja Ramanandi
  • 199
  • 2
  • 5
2

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;

Malte Hartwig
  • 4,477
  • 2
  • 14
  • 30
2

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)
Vipin CP
  • 3,642
  • 3
  • 33
  • 55
1

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.

GYaN
  • 2,327
  • 4
  • 19
  • 39
1

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();
1

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
Gani
  • 422
  • 1
  • 8
  • 16