在项目中,我有一个YAML文件是这样的: 服务: 网址:http://10.10.100.09/service/ping如何在springboot应用程序中从yaml文件读取属性值?
目前我有设置我的测试是这样的:
@RunWith(SpringRunner.class)
@SpringBootTest(properties =
{"service.url=http://10.10.100.09/service/ping"},webEnvironment =
SpringBootTest.WebEnvironment.RANDOM_PORT)
public abstract class BaseIntegration {
@Value("${local.server.port}")
private int serverPort;
@Before
public void setup() {
RestAssured.port = serverPort;
}
}
我的测试被延长BaseIntegration类和测试代码驻留在那里。
问题:如何从配置文件直接读取url属性,而不是在测试中对其进行硬编码?
我曾尝试使用@SpringBootApplication注释,但在开始测试时发生错误。
你想读从默认的'/ src目录/主/资源/ application.yml'文件或财产的一些'/src/test/resources/application-test.yml'? – varren