是否可以将 Spring AOP 方面定义为 Spring JDBC?具体来说,我正在尝试为 NamedParameterJdbcTemplate 设置一个记录器来记录 SQL 查询。下面是我的 XML 配置。
<aop:config>
<aop:aspect id="aspect4" ref="sqlLoggingInterceptor">
<aop:pointcut expression="execution(* org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate..*(..))" id="pointcut3" />
<aop:around pointcut-ref="pointcut3" method="profile" />
</aop:aspect>
</aop:config>
下面是我的拦截器。
@Aspect
@Component
public class SQLLoggingInterceptor {
private final Map<String, SqlTiming> sqlTimings;
public Object profile(ProceedingJoinPoint pjp) throws Throwable {
//logger
}
}
它在创建上下文时抛出以下异常,似乎无法自动装配代理来代替 NamedParameterJdbcTemplate,其中 NamedParameterJdbcTemplate 在许多 DAO 实现中都是自动装配的。
15:06:32,566 INFO [STDOUT] ERROR [ContextLoader] - Context initialization failed org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'com.application.dao.FileStorageDAO': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException:
Could not autowire field: private org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate com.application.dao.FileStorageDAOImpl.jdbcTemplate;
nested exception is java.lang.IllegalArgumentException: Can not set org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate field
com.application.dao.FileStorageDAOImpl.jdbcTemplate to $Proxy166
None
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)