我嘗試在Spring Transactional Test中使用DBUnit填充數據庫表。 數據源是一個TransactionAwareDataSourceProxy。所以我會把這個源給DBUnit,而不是填充表應該是可見的後jdbcTemplate查詢?DBUnit更改在事務性彈簧測試中不可見
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"many contexts"})
@TransactionConfiguration(transactionManager = "transactionManager")
@Transactional
public class DBTest {
@Autowired(required = true)
TransactionAwareDataSourceProxy dataSource;
private JdbcTemplate jdbcTemplate;
@Autowired(required = true)
public void setJdbcTemplate(TransactionAwareDataSourceProxy dataSource) {
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
@Autowired(required = true)
SessionFactory sessionFactory;
@Test
@Transactional
public void test() throws Exception {
IDatabaseConnection dbConn = new DatabaseDataSourceConnection(dataSource);
DatabaseOperation.CLEAN_INSERT.execute(dbConn, new XmlDataSet(ClassLoader.getSystemResourceAsStream("TABLE.xml")));
System.out.println("Es wurden gefunden : " + this.jdbcTemplate.queryForInt("select count(*) from TABLE"));
System.out.println("blaaa");
}
查詢總是返回0. 我在想什麼?
聽起來像一個很好的bug已修復!:-) – Jeff