当前位置:主页 > 软件编程 > JAVA代码 >

Spring整合junit的配置过程图解

时间:2020-12-25 11:52:28 | 栏目:JAVA代码 | 点击:

配置步骤:

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及以上!!!

您可能感兴趣的文章:

相关文章