【发布时间】:2021-06-13 04:51:45
【问题描述】:
我使用的是 Spring-Boot 2.2.4.RELEASE 版本,我决定升级到 2.4.2 版本,因为不是发布版本。我的问题开始是因为我有两个配置文件,一个我使用 configserver,另一个我有一个内存数据库配置为类测试。
src/main/resources/application.properties:
...
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-Boot 测试类的更新之前,它总是采用正确的配置文件,但现在它正在获取 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;
从一个版本到另一个版本的哪些变化破坏了我的项目?
【问题讨论】:
标签: spring-boot spring-boot-test