提问者:小点点

未找到Spring Boot活动配置文件


Spring2.4.5。

正在尝试运行测试示例。

2022-06-30 21:58:39.897  INFO   --- [    Test worker] .b.t.c.SpringBootTestContextBootstrapper : Neither @ContextConfiguration nor @ContextHierarchy found for test class [dataset.status.dashboard.api.repository.StatusRepositoryIntegrationTest], using SpringBootContextLoader
2022-06-30 21:58:39.901  INFO   --- [    Test worker] o.s.t.c.support.AbstractContextLoader    : Could not detect default resource locations for test class [dataset.status.dashboard.api.repository.StatusRepositoryIntegrationTest]: no resource found for suffixes {-context.xml, Context.groovy}.
2022-06-30 21:58:39.902  INFO   --- [    Test worker] t.c.s.AnnotationConfigContextLoaderUtils : Could not detect default configuration classes for test class [dataset.status.dashboard.api.repository.StatusRepositoryIntegrationTest]: StatusRepositoryIntegrationTest does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
2022-06-30 21:58:39.961  INFO   --- [    Test worker] .b.t.c.SpringBootTestContextBootstrapper : Found @SpringBootConfiguration company.status.dashboard.api.App for test class dataset.status.dashboard.api.repository.StatusRepositoryIntegrationTest
2022-06-30 21:58:40.013  INFO   --- [    Test worker] .b.t.c.SpringBootTestContextBootstrapper : Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener, org.springframework.boot.test.autoconfigure.webservices.client.MockWebServiceServerTestExecutionListener, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener, org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.event.ApplicationEventsTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener, org.springframework.test.context.event.EventPublishingTestExecutionListener]
2022-06-30 21:58:40.022  INFO   --- [    Test worker] .b.t.c.SpringBootTestContextBootstrapper : Using TestExecutionListeners: [org.springframework.test.context.web.ServletTestExecutionListener@5be3295e, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@48ec863b, org.springframework.test.context.event.ApplicationEventsTestExecutionListener@37762e2a, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener@4db30010, org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener@f586921, org.springframework.test.context.support.DirtiesContextTestExecutionListener@23a9fbaf, org.springframework.test.context.transaction.TransactionalTestExecutionListener@2528968e, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener@70cea1bb, org.springframework.test.context.event.EventPublishingTestExecutionListener@3c93dfe2, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener@500b2f5c, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener@31f64f35, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener@3430e3c9, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener@16fe5662, org.springframework.boot.test.autoconfigure.webservices.client.MockWebServiceServerTestExecutionListener@1f06ea2e, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener@1c8a911c]
2022-06-30 21:58:40.025  INFO   --- [    Test worker] .b.t.c.SpringBootTestContextBootstrapper : Neither @ContextConfiguration nor @ContextHierarchy found for test class [dataset.status.dashboard.api.repository.StatusRepositoryIntegrationTest$FindFirstDailyDeliveryStatusesByDatasetUnitWithinTimeRange], using SpringBootContextLoader
2022-06-30 21:58:40.025  INFO   --- [    Test worker] o.s.t.c.support.AbstractContextLoader    : Could not detect default resource locations for test class [dataset.status.dashboard.api.repository.StatusRepositoryIntegrationTest$FindFirstDailyDeliveryStatusesByDatasetUnitWithinTimeRange]: no resource found for suffixes {-context.xml, Context.groovy}.
2022-06-30 21:58:40.026  INFO   --- [    Test worker] t.c.s.AnnotationConfigContextLoaderUtils : Could not detect default configuration classes for test class [dataset.status.dashboard.api.repository.StatusRepositoryIntegrationTest$FindFirstDailyDeliveryStatusesByDatasetUnitWithinTimeRange]: FindFirstDailyDeliveryStatusesByDatasetUnitWithinTimeRange does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
2022-06-30 21:58:40.027  INFO   --- [    Test worker] .b.t.c.SpringBootTestContextBootstrapper : Found @SpringBootConfiguration company.status.dashboard.api.App for test class dataset.status.dashboard.api.repository.StatusRepositoryIntegrationTest$FindFirstDailyDeliveryStatusesByDatasetUnitWithinTimeRange
2022-06-30 21:58:40.029  INFO   --- [    Test worker] .b.t.c.SpringBootTestContextBootstrapper : Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener, org.springframework.boot.test.autoconfigure.webservices.client.MockWebServiceServerTestExecutionListener, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener, org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.event.ApplicationEventsTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener, org.springframework.test.context.event.EventPublishingTestExecutionListener]
2022-06-30 21:58:40.029  INFO   --- [    Test worker] .b.t.c.SpringBootTestContextBootstrapper : Using TestExecutionListeners: [org.springframework.test.context.web.ServletTestExecutionListener@14f0dd2a, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@6c6b8304, org.springframework.test.context.event.ApplicationEventsTestExecutionListener@370431a5, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener@491f8897, org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener@5b140513, org.springframework.test.context.support.DirtiesContextTestExecutionListener@6b57ced6, org.springframework.test.context.transaction.TransactionalTestExecutionListener@7dc84300, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener@48a6371e, org.springframework.test.context.event.EventPublishingTestExecutionListener@33e18f84, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener@6695c650, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener@59fa49c1, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener@201d9b27, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener@1f3fbd0f, org.springframework.boot.test.autoconfigure.webservices.client.MockWebServiceServerTestExecutionListener@57d05ffe, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener@5cefa084]
2022-06-30 21:58:40.183  INFO 69695 --- [    Test worker] .StatusRepositoryIntegrationTest : Starting StatusRepositoryIntegrationTest using Java 11.0.15 on C12346 with PID 69695 (started by alex in /Users/alex/projects/status-dashboard-api)
2022-06-30 21:58:40.183  INFO 69695 --- [    Test worker] .StatusRepositoryIntegrationTest : The following profiles are active: local

测试的配置取自main.java.resources.application-local.properties,而必须取自test.java.resources文件夹。

我尝试了不同的选项<code>SPRING.PROFILES。活动,spring.profiles。活动SPRING_PROFILES_active在IntelliJ Idea的运行/调试配置窗口中具有值测试,但确实有所帮助。

“我要运行的测试”具有以下注释:

@ExtendWith(SpringExtension.class)
@SpringBootTest
@TestPropertySource(locations = {"classpath:application-integration.properties"})
class StatusRepositoryIntegrationTest {

共1个答案

匿名用户

spring.profiles。活动是指如果您未配置另一个,则当前将处于活动状态。如果您想使用其他配置文件运行,请参见此。

当然,如果您配置另一个配置文件,则必须应用-

您不需要< code>@TestPropertySource,因为Spring会在测试和主文件夹下找到它。如果在主文件和测试文件中有两个同名的文件,我注意到它们会互相覆盖。我没有测试这个配置是作为一个完整的文件被覆盖还是仅仅通过测试来扩展。

如果您只想运行测试或将设置应用于特定配置文件,则需要@ActiveProfile(“配置文件”)。

要了解有关配置文件的更多信息,请阅读此。

如果我们看一下提到的例子。

@ExtendWith(SpringExtension.class)
@SpringBootTest
@ActiveProfile("integration")
class StatusRepositoryIntegrationTest { ... }

mvn/gradle测试命令-Dspring.profiles。活动=集成--spring.profiles.active=集成