Spring整合junit Spring整合junit的配置过程图解

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

Spring整合junit Spring整合junit的配置过程图解

  2021-04-21 我要评论

配置步骤:

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

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们