一嘲玫、獲取config.properties中的數(shù)據(jù)
1. 在resources目錄下配置config.properties文件
# 人才庫入職
talentPool.fullSpell = autotest
talentPool.idCardEndDate = 2020-04-29
talentPool.baseRegionCode = MRYXHB
2. 添加注解:在LopApplication添加注解
@PropertySource("classpath:config.properties")
public class LopApplication {
public static void main(String[] args) {
SpringApplication.run(LopApplication.class, args);
}
}
3. 在用例中引用數(shù)據(jù)
/ 調(diào)用錄用員工接口
EmployNormalBody body = new EmployNormalBody();
body.setLabourName(environment.getProperty("talentPool.labourName"));
body.setBaseStationCode(environment.getProperty("talentPool.baseStationCode"));
Response res = context.getBean(EmployNormal.class).setBody(body).request();
Assert.assertEquals(res.getStatusCode(), 200, "人才庫-錄用人員,返回狀態(tài)碼!=200");
二、讀取config.properties亂碼問題
1. 當(dāng)配置文件為中文的時(shí)候,會(huì)出現(xiàn)亂碼的問題
2. 解決方式:在application類中的注解后添加encoding = "utf-8"
@PropertySource(value = "classpath:config.properties", encoding = "utf-8")
public class LopApplication {
...
}