测试类注入Bean失败,Could not autowire, No bean of 'XxxService' type found

发布时间 2023-12-11 17:58:11作者: ashet

Spring Boot 2.2 是第一个正式支持 JUnit 5 的版本。

因此在写测试类的时候,JUnit4和JUnit5是有一点区别的。JUnit4需要需要两个注解

@SpringBootTest
@Runwith(SpringRunner.class)

Junit5的测试类则只需要一个注解

@SpringBootTest