spring jdbc踩坑日记,new JdbcTemplate 为null导致UserDao一直为null

时间:2024-04-17 12:37:00
  private DataSource datasource;
private JdbcTemplate jdbcTemplateObject; //设置注入
public void setdatasource(DataSource ds) {
this.datasource = ds;
System.out.println("xxxxxxxxxxxxxxxxx");
System.out.println(ds);
this.jdbcTemplateObject = new JdbcTemplate(datasource);
}

代码如上

排查半天发现 spring注入时,名称的大小写必须为峰驼式

改成

 private DataSource datasource;
private JdbcTemplate jdbcTemplateObject; //设置注入
public void setDataSource(DataSource ds) {
this.datasource = ds;
System.out.println("xxxxxxxxxxxxxxxxx");
System.out.println(ds);
this.jdbcTemplateObject = new JdbcTemplate(datasource);
}

成功查询