您的位置:首頁/技術文章
文章詳情頁

Spring整合junit的配置過程圖解

瀏覽:3日期:2023-09-20 09:29:01

配置步驟:

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提供的,這樣就可以創建容器了:

Spring整合junit的配置過程圖解

3.告知Spring的運行器,spring的容器創建是基于xml的還是基于注解的,并且說明位置;

@ContextConfiguration

基于xml:location:指定xml文件的位置,加上classpath關鍵字,表示在類路徑下

Spring整合junit的配置過程圖解

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

Spring整合junit的配置過程圖解

4.注意!當我們使用spring 5.x版本的時候,要求junit的jar必須是4.12及以上?。?!

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: Spring
相關文章:
国产综合久久一区二区三区