java - 引起原因:java.lang.IllegalArgumentException:错误::0在切入点中正式未绑定(bind)

标签 java spring-boot aop

我已经检查过其他类似的问题,但似乎都不适用。

我有我的服务类:

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 type ProceedingJoinPoint, which is a subclass of JoinPoint

这被记录为主题建议参数的延续,该主题引用了以下内容: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/

相关文章:

java - 尝试运行 android 教程 Form stuff 时出现未定义错误

java - Spring Data MongoDB - 将二进制数据附加到现有的 GridFS 文件

java - 如何模拟 org.springframework.core.io.Resource 对象?

java - 在命令 dspring.config.loc 之后覆盖 application.property 文件

java - 包内所有方法的@AspectJ 切入点

java - 在 spring 中防止来自 Controller 的 dao 调用

java - 运行类测试的输出是什么? (Java,抽象类)

java - 在java程序中引入延迟

javax.validation 2.0.1 List<Object> 在 spring boot 中不起作用

java - MethodInterceptor 中的依赖注入(inject)