Spring-Junit

整合Junit

  1. 导入jar包

         基本 :4+1

         测试:spring-test...jar

1.让Junit通知spring加载配置文件

2.让spring容器自动进行注入

  1. 修改测试类

@RunWith(SpringJUnit4ClassRunner.class)

@ContextConfiguration(locations="classpath:applicationContext.xml")

在src下面要加locations

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);

    }

 

}

 

全部评论

相关推荐

苗条的伊泽瑞尔最喜欢...:同28届被压力了,电科✌就不能去卷算法吗?把Java留给我们双非卷
投递快手等公司10个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务