关于spring中测试


1.首先导入相应的jar包

org.springframework
spring-test
5.3.13

junit
junit
4.12
test
2.需要相应的注解

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:applicationContext.xml")
public class Test02 {
@Autowired //注入相应的对象
private JdbcTemplate jdbcTemplate;
@Test
public void m1(){
int i = jdbcTemplate.update("update user set name = ? where id = ?", "小明", 15);
System.out.println(i);
}

}

关于@ConbtextConfiguration()中路径配置问题
(1) @ContextConfiguration(value="/applicationContext.xml")
(2)@ContextConfiguration(location="/applicationContext.xml")
(3)@ContextConfiguration("classpath:applicationContext.xml")
(4)@ContextConfiguration("/applicationContext.xml")



相关