Junit4 单元测试注入bean失败
一、报错截图
二、单元测试截图
三、解决
@SpringBootTest(classes = XxxApplication.class) 改为 @SpringBootTest(classes = XxxApplication.class, webEnvironment=SpringBootTest.WebEnvironment.RANDOM_PORT)
@SpringBootTest(classes = XxxApplication.class) 改为 @SpringBootTest(classes = XxxApplication.class, webEnvironment=SpringBootTest.WebEnvironment.RANDOM_PORT)