//Dao接口实现类,注入 jdbcTemplate
1. @Autowired
private JdbcTemplate jdbcTemplate;
//错误示范,不能直接new,应该交给IOC处理
2.AccountImp accountImp = new AccountImp();
//正确做法
3.ApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring.xml");
AccountImp accountImp = (AccountImp) applicationContext.getBean("accountImp");
或者
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:spring.xml"})
public class PublicTest {
}
public class AccountCURD extends PublicTest {
@Autowired
AccountImp accountImp;
}
jdbcTemplate通过@Autowired自动注入时,值为null的问题
于 2022-02-18 18:08:19 首次发布