[英]Spring AOP Aspect used in JdbcOperations not invoked
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>我想做这样的事情<\/strong>:
http<\/a> :\/\/www.gotoquiz.com\/web-coding\/programming\/java-programming\/log-sql-statements-with-parameter-values-filled-in-spring-jdbc\/
I'm using a Generic Abstract Class for all my DAOS我正在为我的所有 DAOS 使用通用抽象类
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. 您的aop表达式被定义为JdbcOperation的切入点。*这是一个接口,并且不建议接口调用。
AspectJ can intercept pointcuts in the spring framework for spring-managed-beans. AspectJ可以在Spring框架中拦截spring-managed-beans的切入点。 If the bean is not spring managed you'll need to manually register it using ProxyFactoryBean/ProxyFactory for advisal.
如果bean不是spring管理的,你需要使用ProxyFactoryBean / ProxyFactory手动注册它以获取建议。 In your case you already have a bean implementing the JdbcOperations interface registered in your spring application-context.
在您的情况下,您已经有一个bean实现了在spring应用程序上下文中注册的JdbcOperations接口。
As per your problem changing the pointcut to use any implementation of the JdbcOperations interface ( the jdbcTemplate
bean definition ) should solve your problem. 根据您的问题,更改切入点以使用JdbcOperations接口的任何实现(
jdbcTemplate
bean定义)应该可以解决您的问题。
For example 例如
@Before("execution(* org.springframework.jdbc.core.JdbcOperations+.*(..))")
you lost 1 .*
in the expression,it should be你失去了 1
.*
在表达式中,它应该是
// 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
当我看到这个答案时,这个答案意外地出现了,链接在这里
https://stackoverflow.com/questions/58282255/how-to-intercept-jdbctemplate-whose-instance-is-created-by-myself
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.