Spring整合Junit的配置
步骤:
1. 导入spring整合junit的jar(坐标)和junit的jar包
2. 使用Junit提供的一个注解把原有的main方法替换了。替换成spring提供的
* @@RunWith(SpringJUnit4ClassRunner.class)
3. 告诉soring运行期,spring和ioc创建是基于xml还是注解的,并且说明位置
* @ContextConfiguration()
* locations: 指定xml文件的位置,加上classpath关键字,表示在类路径下
* eg:@ContextConfiguration(locations = "classpath:bean.xml")
* 注意:"classpath:此处不能有空格bean.xml"
* classes:指定注解类所在地位置.class
* eg: @ContextConfiguration(classes= SpringConfig.class)
* 注意:使用spring5.x版本,整合junit时,要求junit的jar包必须是4.12或者以上版本,否则会报错。
1. 在pox.xml中导入spring整合junit的jar(坐标)和junit的jar包
<!--spring依赖的jar包-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.1.12.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>5.1.12.RELEASE</version>
</dependency>
<!--junit依赖的jar包-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
2. 使用Junit提供的一个注解把原有的main方法替换了,替换成spring提供的
3. 告诉soring运行期,spring和ioc创建是基于xml还是注解的,并且说明位置
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/84659.html