spring与mybatis整合后,测试数据库连接时,无法添加注解@ContextConfiguration和RunWith,dataSource出现空指针异常
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:spring-persist-mybatis.xml"})
public class ConnectionTest {
@Autowired
private DataSource dataSource;
@Test
public void test() throws SQLException {
Connection connection = dataSource.getConnection();
System.out.println(connection);
}
}
原因:
对maven的依赖传递不清晰,
导致子工程中没有正确添加junit和spring-test依赖