在項目中,我有一個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