jdbcTemplate通过@Autowired自动注入时,值为null的问题

Posted Vodka~

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了jdbcTemplate通过@Autowired自动注入时,值为null的问题相关的知识,希望对你有一定的参考价值。

//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的问题的主要内容,如果未能解决你的问题,请参考以下文章