Spring Actuator - 如何在测试中排除HealthEndpoint自动装配

时间:2017-10-26 09:40:19

标签: spring spring-mvc testng spring-test

我正在尝试运行测试但是当我尝试运行它时遇到异常Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.boot.actuate.endpoint.HealthEndpoint' available:

我的主文件夹中有两个包com.test.datacom.test.health。我的主要Application课程位于com.test.data。在com.test.health我有一个名为StartupHousekeeper implements ApplicationListener<ApplicationReadyEvent>且自动装配HealthEndpoint的班级,如下所示

@Component
public class StartupHousekeeper implements ApplicationListener<ApplicationReadyEvent> {
    @Autowired
    private HealthEndpoint healthEndpoint;
}

在测试中我有ControllerIntegrationTest这是配置类,代码如下。即使我没有添加com.test.health package,它仍然会抛出NoSuchBeanDefinitionException

@Profile("controller-integration-test")
@ComponentScan(basePackages = {"com.test.data"})
@Configuration
public class ControllerIntegrationTest {
}

我的实际测试课程在

之下
@TestExecutionListeners(MockitoTestExecutionListener.class)
@ActiveProfiles({"controller-integration-test"})
@ContextConfiguration(classes = ControllerIntegrationTest.class)
@WebMvcTest(value = AdminUserController.class, secure = false, excludeAutoConfiguration = {HealthIndicatorAutoConfiguration.class, HibernateJpaAutoConfiguration.class, FlywayAutoConfiguration.class, DataSourceAutoConfiguration.class})
public class AdminUserControllerTest extends AbstractTestNGSpringContextTests implements TestConstants {}

当我尝试运行时org.springframework.test.context.testng.AbstractTestNGSpringContextTests#springTestContextPrepareTestInstance由于上述异常而无法运行

enter image description here

0 个答案:

没有答案