java - 将 spring 配置文件添加到 SpringBootTest 中的现有配置文件中

标签 java spring spring-boot testing spring-boot-test

我有一个 SpringBootTest,我想在现有配置文件中添加一个 spring-profile 以进行特定测试。我试过@SpringBootTest(webEnvironment = RANDOM_PORT, properties = "spring.profiles.include=my-second-profile") https://github.com/spring-projects/spring-boot/issues/7668 中建议的但这根本不起作用。现在只有包含的配置文件处于 Activity 状态。因此,我的上下文无法启动,因为默认 Activity 配置文件中所需的属性丢失。有谁知道如何解决这个问题吗?

谢谢!

最佳答案

properties 需要一个数组 String[],而不是单个对象 String

@SpringBootTest(webEnvironment = RANDOM_PORT,properties = {"spring.profiles.include=my-second-profile"})

{} 包围您的字符串,它应该可以工作。

关于java - 将 spring 配置文件添加到 SpringBootTest 中的现有配置文件中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60560012/

相关文章:

Spring Boot MVC,没有返回我的观点

java - 是否可以使用 thymeleaf 和 spring 将 utf-8 编码的 html 代码注入(inject) html 页面

java - 在 Spring Webflux 中添加的多个 cookie 未合并到单个 HTTP header 中

spring - WebFilter bean 在安全的 Spring Boot Webflux 应用程序中调用了两次

Java-按键事件监听器

java - 无法让 springfox-swagger-ui 与 Spring MVC 一起工作

java - 在for循环中用不同的身份膨胀 View ?

java - 无法将 'logging.level.com.netflix.eureka' 下的属性绑定(bind)到 org.springframework.boot.logging.LogLevel

spring - 如何在独立的 Turbine 应用程序中激活/turbine.stream 端点

spring - 我可以只使用 Spring Boot Starters 来进行依赖管理吗?