最近在学习Spring框架,学到JdbcTemplate在Dao中的使用时,出现了一个问题:Exception in thread "main" java.lang.IllegalArgumentException: No DataSource specified
现在贴出代码(JdbcTemplateDemo4是一个测试类):
package com.dahua.dao;
import java.util.List;
import com.dahua.domain.Account;
/**
* @Version:1.0
* @Description:账户的持久层接口
* @author:秦雁回
* @Date:2020年6月21日下午5:37:59
*/
public interface IAccountDao {
/**
* @Description:根据id查询账户信息
* @param id
* @return
*/
Account findAccountById(Integer id);
/**
* @Description:根据名称查询账户信息
* 要求:账户名称必须唯一,如果不唯一,应该抛异常
* @param name
* @return
*/
Account findAccountByName(String name);
/**
* @Description:保存账户
* @param account
*/
void saveAccount(Account account);
/**
* @Description:更新账户信息
* @param account
*/
void updateAccount(Account account);
/**
* @Description:删除账户
* @param account
*/
void deleteAccount(Account account);
/**
* @Description:查询所有账户
* @return
*/
List<Account> findAllAccount();
}
package com.dahua.dao.impl;
import java.util.List;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import com.dahua.dao.IAccountDao;
import com.dahua.domain.Account;
/**
* @Version:1.0
* @Description:账户的持久层实现类
* @author:秦雁回
* @Date:2020年6月21日下午5:44:37
*/
public class AccountDaoImpl implements IAccountDao {
private JdbcTemplate jdbcTemplate;
@Override
public Account findAccountById(Integer id) {
List<Account> accounts = jdbcTemplate.query("select * from account where id = ?", new BeanPropertyRowMapper<Account>(Account.class), id);
return accounts.isEmpty()?null:accounts.get(0);
}
@Override
public Acco