以下是建议
@AfterReturning(
pointcut = "execution(public java.util.List<me.mikholskiy.domains.Customer> me.mikholskiy.daos.CustomerDao.getAll())",
returning = "resultList")
public void adviceBeforeGetAllCustomersFromDatabase(JoinPoint joinPoint,
List<Customer> resultList) {
// ...
}因此,当我在没有returning参数的情况下使用这个通知注释时,它会像预期的那样工作。但是,当我想将返回结果绑定到这个建议时,什么都不会发生。它甚至没有被执行过。
以下是此建议的目标方法:
@Override
public List<Customer> getAll() {
return sessionFactory.getCurrentSession()
.createQuery("from Customer", Customer.class)
.list();
}我使用这个依赖项
org.springframework:spring-webmvc:5.3.17
org.springframework:spring-aspects:5.3.17
org.aspectj:aspectjweaver:1.9.7发布于 2022-03-19 12:05:49
无法匹配类型List<Customer>,因为子句还将匹配限制为只返回指定类型的值的方法执行(在本例中为__Object或其子类型,这将匹配任何返回值)。
因此,在您的代码中,而不是:
public void adviceBeforeGetAllCustomersFromDatabase(
JoinPoint joinPoint, List<Customer> resultList) {
...试着:
public void adviceBeforeGetAllCustomersFromDatabase(
JoinPoint joinPoint, Object resultList) {
...https://stackoverflow.com/questions/71537092
复制相似问题