我正在尝试使用AbstractTransactionalJUnit4SpringContextTests
. 我想使用executeSQLScript
这个类的方法。
但是,当executeSQLScript
调用方法时,它会抛出,NullPointerException
因为simpleJdbcTemplate
类的参数AbstractTransactionalJUnit4SpringContextTests
没有被初始化。
我的代码如下所示:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({"classpath:test-services-spring-context.xml"})
@TransactionConfiguration(transactionManager = "promoTransactionManager")
public class PromoBrickDAOIT extends AbstractTransactionalJUnit4SpringContextTests {
@Autowired
private PromoBricksDAO promoBricksDAO;
@Before
public void setUp(){
executeSqlScript("classpath:testdata/sql/PromoBrick_Create.sql", false);
}
@After
public void tearDown(){
}
@Test
public void testPromoBrickGivenBrowseTaxonomyNodeId(){
String btxNodeId = "v1_12";
List<PromoBrick> promoBricks = promoBricksDAO.findByBtxNodeId(btxNodeId);
assertNotNull(promoBricks);
assertEquals(promoBricks.size(), 1);
PromoBrick promoBrick = promoBricks.get(0);
assertNotNull(promoBrick);
}
public void setDataSource (@Qualifier("promoDataSource") DataSource dataSource) {
super.setDataSource(dataSource);
}
}
在此先感谢您的帮助!