导入jar包
基本 :4+1
测试:spring-test...jar
1.让Junit通知spring加载配置文件
2.让spring容器自动进行注入
修改测试类
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations="classpath:applicationContext.xml")
public class TestApp {
@Autowired //与junit整合,不需要在spring xml配置扫描
private AccountService accountService;
@Test
public void demo01(){
// String xmlPath = "applicationContext.xml";
// ApplicationContext applicationContext = new ClassPathXmlApplicationContext(xmlPath);
// AccountService accountService = (AccountService) applicationContext.getBean("accountService");
accountService.transfer("jack", "rose", 1000);
}
}