java-如何在spring-boot 1.4.3中覆盖spring-boot应用程序属性
作者:互联网
在我们的项目中,我们通过覆盖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"})
标签:spring-boot,testing,integration-testing,spring,java 来源: https://codeday.me/bug/20191111/2022452.html