【Exception】java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, ...

案發現場

@RunWith(SpringRunner.class)
@SpringBootTest
public class Test1 {
	@Test
	public void getLines() throws IOException, InterruptedException{
		Cal cal = new CalImpl();
		System.out.println(cal.add(1, 2));
	}
}

解決方案

保證測試類所在的包被main入口掃描到

比如:@ComponentScan掃描的包是com.itplh, 而單元測試的類所在包爲org.itplh, 這樣就會導致報錯

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章