I am trying to do test as follow:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {
"classpath:test-context.xml"
})
public class EventTest {
@Autowired private DataSource dataSource;
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
@Test
public void testEvent(){
String sql = "select * from event";
List<Map<String, Object>> resultSet = jdbcTemplate.queryForList(sql);
System.out.println(resultSet);
}
}
In test-context.xml
I have
<jdbc:embedded-database id="datasource">
<jdbc:script location="classpath:schema.sql" />
<jdbc:script location="classpath:data.sql" />
</jdbc:embedded-database>
Still I am getting exception
java.lang.IllegalArgumentException: Property 'dataSource' is required
at org.springframework.jdbc.support.JdbcAccessor.afterPropertiesSet(JdbcAccessor.java:134)
at org.springframework.jdbc.core.JdbcTemplate.<init>(JdbcTemplate.java:165)
Any suggestion?
Aucun commentaire:
Enregistrer un commentaire