当前位置: 首页 > 知识库问答 >
问题:

未找到Spring Boot活动配置文件

巫马欣嘉
2023-03-14

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个答案

皇甫德庸
2023-03-14

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

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

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

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

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

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

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

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

 类似资料:
  • 问题内容: 我正在尝试使用Maven 3 在Spring Boot应用程序中设置活动配置文件。在我的pom.xml中,将默认的活动配置文件和属性spring.profiles.active设置 为development: 但是每次我运行应用程序时,都会在日志中收到以下消息: 并且将SpringBoot配置文件设置为默认值(读取application.properties而不是application

  • 我已经将其隔离到一个非常简单的测试项目中,该项目除了简单的log4j2test配置使用之外没有其他用途。文件目录结构: 建筑sbt: log4j2.xml内容复制/粘贴从示例在官方留档:https://logging.apache.org/log4j/2.x/manual/configuration.html SimpleMain。斯卡拉: 我跑步与 输出:

  • 我似乎不能在本地工作,即使同样的WAR在远程服务器上也能工作。当我在本地访问我的应用程序时,我得到了“没有找到上下文根”的错误。自由档案版本是8.5.5.5。 以下是相关文件: 服务器.xml 留言.log ibm-web-bnd.xml ibm-web-ext.xml

  • 我试图在没有aws概要文件设置的远程无服务器服务器上运行python代码。查看boto3文档后,我会说: 我将获得一个新的boto3名称配置文件,但我得到一个错误: secret_class=get_secret(名称、地区、概况) 文件“/metaflow/func\u get\u aws\u secrets.py”,第45行,在get\u secret session=boto3.sessio

  • 问题内容: 输出: 问题答案: 您将获得“ ”警告,如果你没有一个文件在你的主目录,或者如果你不指定pylint的说法。 要取消显示该消息,请在* nix上:

  • 这是我的配置文件: 日志配置文件读起来非常清楚,因为它使用my/log目录中定义的模式正确地写入。 这是我在代码中实例化它的方式: