SpringBootTest测试类报错:Suppressed: java.lang.IllegalStateException: Unable to find a @SpringBootCon

In a particularly simple mybatisPlus test class, an error is reported during unit testing Suppressed: java.lang.IllegalStateException: Unable to find a @SpringBootCon. In addition, the automatic injection of mapper in the test class will prompt a failure.
Insert picture description here
There are many opinions on the Internet. There may be many reasons for this error. In my case, the directory of the test class and the springboot main startup class are inconsistent.
Insert picture description hereAs you can see, my main startup class is in the com.wuwl directory, and at the beginning, my main test class is placed in the root directory.
Put the main test class in the com.wuwl directory, you can find that the mapper in the test class automatically injects errors and disappears. Therefore, attention should be paid to this knowledge point that has not been paid attention to before.

Guess you like

Origin blog.csdn.net/qq_41885819/article/details/107884206