码迷,mamicode.com
首页 > 编程语言 > 详细

Spring整合junit的配置

时间:2020-02-24 00:48:12      阅读:86      评论:0      收藏:0      [点我收藏+]

标签:end   span   http   pre   version   Spring 5   spring   str   work   

配置步骤:

1.导入Spring整合Junit的jar(坐标):

 <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-test</artifactId>
          <version>5.0.2.RELEASE</version>
          <scope>test</scope>
      </dependency>

2.使用Junit提供的一个注解@Runwith()把原有的main方法替换成spring提供的,这样就可以创建容器了:

技术图片

3.告知Spring的运行器,spring的容器创建是基于xml的还是基于注解的,并且说明位置;

@ContextConfiguration

 基于xml:location:指定xml文件的位置,加上classpath关键字,表示在类路径下

技术图片

 基于注解:classes:指定注解类所在的位置

技术图片

4.注意!当我们使用spring 5.x版本的时候,要求junit的jar必须是4.12及以上!!!

Spring整合junit的配置

标签:end   span   http   pre   version   Spring 5   spring   str   work   

原文地址:https://www.cnblogs.com/iceywu/p/12355054.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!