springboot项目test类中的@Autowire无法自动注入

时间:2024-05-23 14:52:25

expected at least 1 bean which qualifies as autowire candidate

原因:
启动类与测试类同名
@SpringBootTest注解中的ApplicationMain.class无法识别是哪个类
更改其中一个类名即可

另外注意测试类和启动类需要在同一级(包)

springboot项目test类中的@Autowire无法自动注入