I want to do something like this<\/strong> : http:\/\/www.gotoquiz.com\/web-coding\/programming\/java-programming\/log-sql-statements-with-parameter-values-filled-in-spring-jdbc\/<\/a>
public abstract class GenericDaoImpl {
@Autowired
protected JdbcTemplate jdbcTemplate;
}
@Repository
public class UserDAOImpl extends GenericDaoImpl implements UserDAO{
}
Your aop expression is defined as a pointcut to a JdbcOperation.* which is an interface, and interface calls are not advised.
AspectJ can intercept pointcuts in the spring framework for spring-managed-beans. If the bean is not spring managed you'll need to manually register it using ProxyFactoryBean/ProxyFactory for advisal. In your case you already have a bean implementing the JdbcOperations interface registered in your spring application-context.
As per your problem changing the pointcut to use any implementation of the JdbcOperations interface ( the jdbcTemplate
bean definition ) should solve your problem.
For example
@Before("execution(* org.springframework.jdbc.core.JdbcOperations+.*(..))")
you lost 1 .*
in the expression,it should be
// this works fine
@Before("execution(* org.springframework.jdbc.core..*JdbcOperations.*(String, ..))")
But you wrote like
// this's not good
@Before("execution(* org.springframework.jdbc.core.JdbcOperations.*(..))")
This answer came to me unexpectedly when I saw this ,link here https://stackoverflow.com/questions/58282255/how-to-intercept-jdbctemplate-whose-instance-is-created-by-myself
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.