![](/img/trans.png)
[英]Modify value from class with @AfterReturning in Spring AOP
[英]@Afterreturning advice from Spring AOP doesn't work when I bind returning result to it
這是建議
@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
無法匹配類型List<Customer>
,因為returning
子句還將匹配限制為僅返回指定類型( Object
或其子類型,在本例中為匹配任何返回值)的值的方法執行。
因此,在您的代碼中,而不是:
public void adviceBeforeGetAllCustomersFromDatabase(
JoinPoint joinPoint, List<Customer> resultList) {
...
嘗試:
public void adviceBeforeGetAllCustomersFromDatabase(
JoinPoint joinPoint, Object resultList) {
...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.