问题
I have made two test methods. One uses JdbcTemplate to make the query while other uses NamedParameterJDBCTemplate.
Using NamedParameterJdbcTemplate:
@Autowired
JdbcTemplate jdbcTemplate;
public Student findById(long id) {
NamedParameterJdbcTemplate apptemplate = new NamedParameterJdbcTemplate(jdbcTemplate.getDataSource());
return apptemplate.queryForObject("select * from student where id="+id, Collections.emptyMap(),
new BeanPropertyRowMapper< Student >(Student.class));
}
Using JdbcTemplate
@Autowired
JdbcTemplate jdbcTemplate;
public Student findById(long id) {
return jdbcTemplate.queryForObject("select * from student where id=?", new Object[] {
id
},
new BeanPropertyRowMapper< Student >(Student.class));
}
I am using below pointcut to intercept:
For JdbcTemplate:
@Pointcut("execution(* org.springframework.jdbc.core.JdbcOperations+.*(..))")
public void forJdbcTemplate() {
}
For NamedParameterJdbcTemplate:
@Pointcut("execution(* org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations+.*(..))")
public void forNamedParameterJdbcTemplate() {
}
Why does my pointcut for JdbcTemplate work but pointcut for NamedParameterJdbcTemplate does not work?
来源:https://stackoverflow.com/questions/52634043/aop-able-to-intercept-jdbctemplate-calls-but-not-namedparameterjdbctemplate-cal