IDEA 解決Failed to load ApplicationContext

在使用Spring Boot時,報錯如下:

Failed to load ApplicationContext;

解決方法:

第一步:pom.xml中添加Junit依賴:

<dependency>
   <groupId>junit</groupId>
   <artifactId>junit</artifactId>
   <version>4.12</version>
   <scope>test</scope>
</dependency>

第二步,測試類添加註解@RunWith和@SpringBootTest:

@RunWith(SpringRunner.class)
@SpringBootTest
class SpringBoot02ConfigApplicationTests {
    @Autowired
	Person person;
	@Test
	void contextLoads() {
		System.out.println (person);
	}

}

參考鏈接:https://junit.org/junit5/docs/current/user-guide/#running-tests-ide

發佈了15 篇原創文章 · 獲贊 8 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章