I am trying to set up a database test using Spring and DBUnit. I have a script to run before each test. The code below works but SimpleJdbcTemplate is deprecated. The method executeSqlScript is being moved to JdbcTestUtil as part of the 3.2 release but we’re on 3.1.x. What to use instead?
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
public class MyTestScript{
@Autowired
public DataSource dataSource;
@Autowired
public Resource script;
@Before
public void setup() {
SimpleJdbcTestUtils.executeSqlScript(
new SimpleJdbcTemplate(dataSource), script, true);
}
@Test
public void testInsert() {
}
}
You should just suppress the warning and go on. Once you switch to Spring 3.2, the transition will be trivial (remove all the
Simpleprefixes). There is no real reason to avoidSimpleJdbcTemplateat all costs in these tests, as its whole functionality is inJdbcTemplateunder the same name.