Spring Actuator 和@DataJpaTest 找不到 CounterService bean

Spring Actuator and @DataJpaTest cannot find CounterService bean

我刚刚在我的 Spring 引导项目中设置了 Spring 执行器,但是现在当我 运行 我的 Jpa 单元测试 spring 抱怨

org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.boot.actuate.metrics.CounterService'

因为找不到

@Resource
CounterService counterService;

这是我的测试class

@RunWith(SpringRunner.class)
@SpringBootTest
@DataJpaTest
@ActiveProfiles("dev")
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
public class MyTestClass {

将主要 class 包含到 @SpringBootTest(classes=MainApplication.java) 或其他 classes 以加载此测试

@RunWith(SpringRunner.class)
@SpringBootTest(classes=MainApplication.java)
@DataJpaTest
@ActiveProfiles("dev")
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
public class MyTestClass {