25

我在aspectJ中有这样的表达:

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

}

Spring 3.0启动时,我收到以下错误

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

10 回答 10

29

可能问题不在于您的切入点,而在于使用该切入点和使用切入点中不存在的参数的建议。只需从建议中删除参数(好吧,或者将其添加到切入点)。

于 2012-09-04T08:44:24.540 回答
14

它是 Joinpoint ("p 小写)

org.aopalliance.intercept.Joinpoint;

更改为 JointPoint("P 大写)

org.aspectj.lang.JoinPoint; 
于 2018-05-03T19:57:10.347 回答
11

该帖子相当陈旧,但为了完整起见,如果您使用@Around 建议,我会添加另一个原因。

根据Spring AspectJ 文档,建议的第一个参数必须是 ProceedingJoinPoint。如果它丢失,您将收到此异常消息。可悲的是,该异常并不指向错误的建议,因此解决该错误是一个偶然的机会。

于 2016-05-11T14:09:42.900 回答
5

由于类的错误导入,我得到了这个错误。我应该导入 import org.aspectj.lang.JoinPoint class ,而是从不同的包中导入了一些其他的 Joinpoint 类。

于 2017-03-31T11:32:03.333 回答
2

我遇到了同样的错误,在我的场景中我使用了两个方法参数

public void methodName(JoinPoint joinPoint ,HttpServletRequest request) throws

我的注释就像

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

作为解决方案,我添加了

参数(请求,..)

@Before("execution(public * com.java.controller.*Controller.*(..)) && args(request,..)")
于 2019-01-28T11:47:38.033 回答
2

有时原因可能是这个。

 public void afterReturning(JoinPoint joinPoint, Object result)

Object result只需按如下方式删除,它就对我有用。

public void afterReturning(JoinPoint joinPoint)
于 2018-10-21T09:24:56.457 回答
2

我也有这个问题,在我的情况下,这是一个错误的导入:org.aopalliance.intercept.Joinpoint;

它需要是:org.aspectj.lang.JoinPoint;

于 2018-01-04T14:58:04.763 回答
1

切入点异常中的正式未绑定也发生在 AOP 中的两个响应中。

原因一:如果在返回通知后没有返回语句

对于基于 XML 的实现

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

对于基于注释的实现

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

原因2:如果没有投掷后投掷建议

对于基于 XML 的实现

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

对于基于注释的实现

@AfterThrowing(  
              pointcut = "execution(* Operation.*(..))",  
              throwing= "error")  //Make sure throwing error is added
于 2018-11-05T06:30:55.297 回答
1

如果您使用的是基于 XML 的配置并且您的配置是这样的:

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

然后在 2 种情况下,您会收到错误消息:

  1. 如果在切入点表达式中,在我们的例子中,方法即 display() 没有定义任何参数,而在实际的类方法中有一些参数。
  2. 如果在之前的通知中,即aop:before,method="before" 没有定义arg-names 并且在实际的通知类中,方法"before" 有一些参数。

最终当 XML 中定义的方法参数与实际方法不匹配时,就会出现这个错误。

于 2018-04-03T10:37:04.370 回答
1

这不是您的回答,但可能会对您有所帮助。

Spring AOP 教程你可以参考这个教程

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

我得到了相同的异常,但是由于WebRequest,我删除了它并使用了替代方法

HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest();
于 2018-04-08T04:55:54.680 回答