欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來到入門教程網(wǎng)!

Java

當前位置:主頁 > 軟件編程 > Java >

springboot單元測試兩種方法實例詳解

來源:本站原創(chuàng)|時間:2020-01-10|欄目:Java|點擊: 次

這篇文章主要介紹了springboot單元測試兩種方法實例詳解,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下

springboot的單元測試,這里介紹兩種方式,一種是在測試類中添加注解;另一種是在代碼中啟動項目的main方法中繼承接口(也可以寫在其他方法中)。

  如 對查看數(shù)據(jù)庫的連接池信息 進行單元測試

1. 在類上使用注解:

  @RunWith(SpringRunner.class)

  @SpringBootTest

@RunWith(SpringRunner.class)
@SpringBootTest
public class RobotsApplicationTests {

  @Autowired
  DataSource dataSource;

  @Test
  public void test(){
    System.out.println(dataSource.getClass());
  }

}

2. 繼承CommandLineRunner接口

CommandLineRunner:表示在項目啟動完成后 會執(zhí)行該功能,只需將測試的內容寫在其run()方法中,如:

@SpringBootApplication
@EnableScheduling
@ComponentScan(basePackages={"com.cmit.hall.plat","com.cmit.hall.pub"}) 
@ServletComponentScan(value= {"com.cmit.hall.pub.interceptor","com.cmit.hall.plat.config","com.cmit.hall.pub.session"})
@EnableRedisHttpSession(maxInactiveIntervalInSeconds=1800)
public class PlatApp implements CommandLineRunner {
  
  @Autowired
  DataSource dataSource;

  public static void main(String[] args) {
    SpringApplication.run(PlatApp.class, args);
  }
  
  @Override
  public void run(String... args) throws Exception {
    System.out.println(">>>>>>>>>>>>>>>服務啟動執(zhí)行,執(zhí)行加載數(shù)據(jù)等操作<<<<<<<<<<<<<");
    System.out.println("DATASOURCE = " + dataSource);
  }
}

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

上一篇:Springboot測試類沒有bean注入問題解析

欄    目:Java

下一篇:Spring @Transactional注解失效解決方案

本文標題:springboot單元測試兩種方法實例詳解

本文地址:http://mengdiqiu.com.cn/a1/Java/8896.html

網(wǎng)頁制作CMS教程網(wǎng)絡編程軟件編程腳本語言數(shù)據(jù)庫服務器

如果侵犯了您的權利,請與我們聯(lián)系,我們將在24小時內進行處理、任何非本站因素導致的法律后果,本站均不負任何責任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權所有