我正在尝试运行测试但是当我尝试运行它时遇到异常Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.boot.actuate.endpoint.HealthEndpoint' available:
我的主文件夹中有两个包com.test.data
和com.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
由于上述异常而无法运行