首先Spring in action例子有个bug
运行程序,出现错误打印
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'namedParameterJdbcTemplate' defined in URL [file:src/test-context.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate]: No default constructor found; nested exception is java.lang.NoSuchMethodException: org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.<init>()
需要修改为
参考Spring持久层(一)
修改之处
1 配置文件,添加bean定义
2 NamedParameterJdbcTemplateProductDao.java源码
3 测试代码