AOP: Able to Intercept JDBCTemplate calls but not NamedParameterJdbcTemplate calls

 ̄綄美尐妖づ 提交于 2020-01-16 08:46:19

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!