gpt4 book ai didi

java - 如何在 spring-boot 1.4.3 中覆盖 spring-boot 应用程序属性

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:36:14 25 4
gpt4 key购买 nike

在我们的项目中,我们通过覆盖 IntegrationTest 注释中的属性来设置我们的集成测试,如下所示:

@RunWith(SpringJunitClassRunner.class)
@IntegrationTest("server.port:0",
"health.hystrix.enabled:false"
.... other properties ....
)
@ActiveProfile("local","no-swagger")
public class IntegrationTest{
}

但是在 spring-boot 1.4 中,@IntegrationTest 注释已被弃用。 Spring 文档建议改用 @SpringBootTest 注释。我的问题是如何使用这个新注释覆盖属性?

最佳答案

我的理解from the docs是您能够覆盖 @SpringBootTest 中的属性。

The @SpringBootTest annotation also has a properties attribute that can be used to specify any additional properties that should be defined in the Environment. Properties are now loaded in the exact same way as Spring’s regular @TestPropertySource annotation.

And also the javadoc of @SpringBootTest says :

@AliasFor(value="value")

public abstract String[] properties

Properties in form key=value that should be added to the Spring Environment before the test runs.

Returns: the properties to add

因此只需覆盖 @SpringBootTest 注解中的属性即可。

@SpringBootTest(properties={"server.port=0"})

关于java - 如何在 spring-boot 1.4.3 中覆盖 spring-boot 应用程序属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41822059/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com