我已经检查过其他类似的问题,但似乎都不适用。
我有我的服务类:
package com.test.demo.service;
import com.test.demo.controller.Controller2;
import com.test.demo.model.SettlementTransaction;
import org.springframework.stereotype.Service;
@Service
public class TestService {
public Controller2.AcctDetails testAcctDeets(Transaction transaction){
以及我的方面:
@AfterReturning(pointcut = "execution(* com.test.demo.service.TestService.testAcctDeets(..))", returning = "response")
public void interceptRequest(Controller2.AcctDetails response, JoinPoint thisJoinPoint) {
System.out.println(thisJoinPoint);
for (Object arg : thisJoinPoint.getArgs()) {
if (arg instanceof String)
System.out.println(" request = " + arg);
}
System.out.println(" response = " + response.toString());
}
但我不断收到错误:
Caused by: java.lang.IllegalArgumentException: error at ::0 formal unbound in pointcut
感谢任何帮助。谢谢!
最佳答案
来自引用文档:Access to the Current
Any advice method may declare, as its first parameter, a parameter of type
org.aspectj.lang.JoinPoint
(note that around advice is required to declare a first parameter of typeProceedingJoinPoint
, which is a subclass ofJoinPoint
这被记录为主题建议参数的延续,该主题引用了以下内容:Spring 提供完全类型化的建议,这意味着您可以在建议签名中声明所需的参数(正如我们之前看到了返回和抛出的示例)。
当一起阅读时,当传递通知参数并且通知方法还具有 JointPoint
或其任何子类作为另一个参数时,后者应声明为第一个参数。
所以在这种情况下,有效的方法签名是
@AfterReturning(pointcut = "execution(* com.test.demo.service.TestService.testAcctDeets(..))", returning = "response")
public void interceptRequest(JoinPoint thisJoinPoint, Controller2.AcctDetails response) {
// ..
}
关于java - 引起原因:java.lang.IllegalArgumentException:错误::0在切入点中正式未绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61777462/