[英]Spring jdbctemplate, datasource, transactionManager
For a test, i have a abstract class. 为了测试,我有一个抽象类。
public abstract class BaseTestClass
private JdbcTemplate jdbcTemplate;
@Autowired
public void setDataSource(DataSource dataSource)
{
this.setJdbcTemplate(new JdbcTemplate(dataSource));
}
...
}
@Transactional
@ContextConfiguration(locations = {"/spring/test/test-dao-context.xml"})
public class TestUser extends BaseTestClass{
...
}
In test-dao-context.xml file, i have my transaction manager and datasource. 在test-dao-context.xml文件中,我有事务管理器和数据源。
SetDataSource is never called, so i get a null pointerException when i try to do a test. 永远不会调用SetDataSource,因此当我尝试进行测试时,我得到一个null pointerException。
You need to run you test with an appropriate runner which is SpringJUnit4ClassRunner
for Spring driven tests. 您需要使用适当的运行程序运行测试,该运行程序是用于Spring驱动的测试的SpringJUnit4ClassRunner
。 Otherwise nothing will get injected anywhere as there is no Spring Container managing all the instances. 否则,任何地方都不会注入任何东西,因为没有Spring Container管理所有实例。
Check Spring Unit Testing for details. 有关详细信息,请检查弹簧单元测试 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.