解決SpringBoot運(yùn)行Test時(shí)報(bào)錯(cuò):SpringBoot Unable to find
SpringBoot運(yùn)行Test時(shí)報(bào)錯(cuò)
運(yùn)行Test時(shí)的報(bào)錯(cuò)信息:SpringBoot Unable to find a @SpringBootConfiguration
錯(cuò)誤詳情
今天做SpringBoot配置郵件發(fā)送的時(shí)候,運(yùn)行測(cè)試類(lèi),報(bào)如下錯(cuò)誤:

說(shuō)找不到@SpringBootConfiguration注解,其實(shí)是有的,檢查了下啟動(dòng)類(lèi)和被測(cè)試類(lèi)的細(xì)節(jié),都沒(méi)問(wèn)題,查詢(xún)的很多CSDN答案都是互相抄來(lái)抄去。。。。比如測(cè)試類(lèi)的包名和啟動(dòng)類(lèi)的包名一致等解決辦法,試了都沒(méi)用。
解決辦法
原來(lái)還要在測(cè)試類(lèi)里制定啟動(dòng)類(lèi)。。。解決辦法很簡(jiǎn)單,把@SpringBootTest()注解改成@SpringBootTest(classes = App.class)就可以了。就像這樣:

注:我這里的啟動(dòng)類(lèi)名為App,更改的時(shí)候根據(jù)自己?jiǎn)?dòng)類(lèi)名來(lái)改

SpringBootTest單元測(cè)試報(bào)錯(cuò)
@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í)行時(shí)間:" + (endTime - startTime));
// long startTime = System.currentTimeMillis();
// johnyService.select1();
// long endTime = System.currentTimeMillis();
// System.err.println("執(zhí)行時(shí)間1:"+(endTime-startTime));
// startTime = System.currentTimeMillis();
// johnyService.select2();
// endTime = System.currentTimeMillis();
// System.err.println("執(zhí)行時(shí)間2:"+(endTime-startTime));
}
@Test
public void check() {
}
@Test
public void register() {
}
@Test
public void detail() {
}
@Test
public void queryCategory() {
}
}

其實(shí)只需要在setting中設(shè)置運(yùn)行test的環(huán)境即可。

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
microlog4android將Android Log日志寫(xiě)到SD卡文件中實(shí)現(xiàn)方法
這篇文章主要介紹了microlog4android將Android Log日志寫(xiě)到SD卡文件中實(shí)現(xiàn)方法的相關(guān)資料,需要的朋友可以參考下2016-10-10
java實(shí)現(xiàn)在普通類(lèi)中注入service或mapper
這篇文章主要介紹了java實(shí)現(xiàn)在普通類(lèi)中注入service或mapper的操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-07-07
SpringBoot自定義HttpMessageConverter操作
這篇文章主要介紹了SpringBoot自定義HttpMessageConverter的操作,具有很好的參考價(jià)值,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-08-08
SpringBoot使用Caffeine實(shí)現(xiàn)內(nèi)存緩存示例詳解
caffeine提供了四種緩存策略:分別為手動(dòng)加載、自動(dòng)加載、異步手動(dòng)加載、異步自動(dòng)加載,這篇文章主要介紹了SpringBoot使用Caffeine實(shí)現(xiàn)內(nèi)存緩存,需要的朋友可以參考下2023-06-06
Hibernate雙向多對(duì)多映射關(guān)系配置代碼實(shí)例
這篇文章主要介紹了Hibernate雙向多對(duì)多映射關(guān)系配置代碼實(shí)例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-10-10
mybatis-plus?查詢(xún)傳入?yún)?shù)Map,返回List<Map>方式
這篇文章主要介紹了mybatis-plus?查詢(xún)傳入?yún)?shù)Map,返回List<Map>方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-12-12

