Spring-启动测试加载application.propertites 错误 - 2.4.2

Spring-Boot Test loading application.propertites wrong - 2.4.2

我使用的是 Spring-Boot 2.2.4.RELEASE 版本,我决定升级到 2.4.2 版本,因为它不是已发布的版本。我的问题开始是因为我有两个配置文件,一个我使用 configserver,另一个我有一个内存数据库配置为 class test.

src/main/resources/application.属性:

...
spring.profiles.active=@activatedProperties@
spring.config.import=optional:configserver:@url@

src/test/resources/application.yml:

spring:
  jpa:
    database-platform: org.hibernate.dialect.H2Dialect
    show-sql: true
    properties:
      hibernate.format_sql: true
      ....
  datasource:
     driver-class-name: org.h2.Driver
     platform: h2
     name: CUP_ORCHESTRATOR
     url: jdbc:h2:mem:CUP_ORCHESTRATOR;DB_CLOSE_DELAY=-1;INIT=CREATE SCHEMA IF NOT EXISTS CUP_ORCHESTRATOR
     initializaion-mode: embedded
     username: sa
     password: 

在我 运行 Spring-启动测试 class 的更新之前,它总是采用正确的配置文件,但现在它正在获取 src/main/resources/application.properties测试:

[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.closeupinternational.cpoprocesscontrol.test.WorkflowServiceTest
18:39:28.943 [main] ERROR o.s.boot.SpringApplication - Application run failed
java.lang.IllegalStateException: Unable to load config data from 'optional:configserver:http://localhost:8888'

工作流服务测试:

@SpringBootTest(properties = "spring.cloud.config.enabled=false")
@TestPropertySource("classpath:application.yml")
@Slf4j
public class WorkflowServiceTest {

    @MockBean
    private SenderConfig senderConfig;

从一个版本到另一个版本有什么变化破坏了我的项目?

将 application.yml 更改为 application.properties,因为 TestPropertySource 注释仅适用于 .properties 文件。