簡體   English   中英

"未調用 JdbcOperations 中使用的 Spring AOP 方面"

[英]Spring AOP Aspect used in JdbcOperations not invoked

我想做這樣的事情<\/strong>: http<\/a> :\/\/www.gotoquiz.com\/web-coding\/programming\/java-programming\/log-sql-statements-with-parameter-values-filled-in-spring-jdbc\/

我有一個 Spring MVC 項目,我正在使用 Spring 4.3.0.RELEASE。

我正在為我的所有 DAOS 使用通用抽象類

public abstract class GenericDaoImpl {
    @Autowired
    protected JdbcTemplate jdbcTemplate;
}


@Repository
public class UserDAOImpl extends GenericDaoImpl implements UserDAO{

}

您的aop表達式被定義為JdbcOperation的切入點。*這是一個接口,並且不建議接口調用。

AspectJ可以在Spring框架中攔截spring-managed-beans的切入點。 如果bean不是spring管理的,你需要使用ProxyFactoryBean / ProxyFactory手動注冊它以獲取建議。 在您的情況下,您已經有一個bean實現了在spring應用程序上下文中注冊的JdbcOperations接口。

根據您的問題,更改切入點以使用JdbcOperations接口的任何實現( jdbcTemplate bean定義)應該可以解決您的問題。

例如

@Before("execution(* org.springframework.jdbc.core.JdbcOperations+.*(..))")

你失去了 1 .*在表達式中,它應該是

// this works fine 
@Before("execution(* org.springframework.jdbc.core..*JdbcOperations.*(String, ..))") 

但是你寫的像

// this's not good 
@Before("execution(* org.springframework.jdbc.core.JdbcOperations.*(..))") 

當我看到這個答案時,這個答案意外地出現了,鏈接在這里https://stackoverflow.com/questions/58282255/how-to-intercept-jdbctemplate-whose-instance-is-created-by-myself

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM