解決SpringBoot運行Test時報錯:SpringBoot Unable to find
SpringBoot運行Test時報錯
運行Test時的報錯信息:SpringBoot Unable to find a @SpringBootConfiguration
錯誤詳情
今天做SpringBoot配置郵件發(fā)送的時候,運行測試類,報如下錯誤:
說找不到@SpringBootConfiguration注解,其實是有的,檢查了下啟動類和被測試類的細節(jié),都沒問題,查詢的很多CSDN答案都是互相抄來抄去。。。。比如測試類的包名和啟動類的包名一致等解決辦法,試了都沒用。
解決辦法
原來還要在測試類里制定啟動類。。。解決辦法很簡單,把@SpringBootTest()注解改成@SpringBootTest(classes = App.class)就可以了。就像這樣:
注:我這里的啟動類名為App,更改的時候根據(jù)自己啟動類名來改
SpringBootTest單元測試報錯
@RunWith(SpringRunner.class) @SpringBootTest(classes = { DataRulesApplication.class }) @EnableAutoConfiguration //@SpringBootTest(classes = { DataRulesApplication.class }) public class HuaboAddressTest extends AbstractTestNGSpringContextTests { @Autowired private HuaboAddressServiceImpl johnyService; @Test public void queryState() { //johnyService.resetAllDistricts(); long startTime = System.currentTimeMillis(); // johnyService.resetAllDistricts(); // johnyService.batchUpdate2(); // johnyService.batchupdate3(); //johnyService.resetAllDistricts(); johnyService.updateBatch(); long endTime = System.currentTimeMillis(); System.out.println("執(zhí)行時間:" + (endTime - startTime)); // long startTime = System.currentTimeMillis(); // johnyService.select1(); // long endTime = System.currentTimeMillis(); // System.err.println("執(zhí)行時間1:"+(endTime-startTime)); // startTime = System.currentTimeMillis(); // johnyService.select2(); // endTime = System.currentTimeMillis(); // System.err.println("執(zhí)行時間2:"+(endTime-startTime)); } @Test public void check() { } @Test public void register() { } @Test public void detail() { } @Test public void queryCategory() { } }
其實只需要在setting中設(shè)置運行test的環(huán)境即可。
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
microlog4android將Android Log日志寫到SD卡文件中實現(xiàn)方法
這篇文章主要介紹了microlog4android將Android Log日志寫到SD卡文件中實現(xiàn)方法的相關(guān)資料,需要的朋友可以參考下2016-10-10java實現(xiàn)在普通類中注入service或mapper
這篇文章主要介紹了java實現(xiàn)在普通類中注入service或mapper的操作,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-07-07SpringBoot自定義HttpMessageConverter操作
這篇文章主要介紹了SpringBoot自定義HttpMessageConverter的操作,具有很好的參考價值,如有錯誤或未考慮完全的地方,望不吝賜教2021-08-08SpringBoot使用Caffeine實現(xiàn)內(nèi)存緩存示例詳解
caffeine提供了四種緩存策略:分別為手動加載、自動加載、異步手動加載、異步自動加載,這篇文章主要介紹了SpringBoot使用Caffeine實現(xiàn)內(nèi)存緩存,需要的朋友可以參考下2023-06-06Hibernate雙向多對多映射關(guān)系配置代碼實例
這篇文章主要介紹了Hibernate雙向多對多映射關(guān)系配置代碼實例,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2020-10-10mybatis-plus?查詢傳入?yún)?shù)Map,返回List<Map>方式
這篇文章主要介紹了mybatis-plus?查詢傳入?yún)?shù)Map,返回List<Map>方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-12-12