配置文件application.properties剥离
Posted wangkc
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了配置文件application.properties剥离相关的知识,希望对你有一定的参考价值。
1、在resources目录下配置application.properties:
test.url=http://127.0.0.1:8888 getCookees.uri=/getCookies login=/login
2、测试代码中使用,
package httpclient; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.util.EntityUtils; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; import java.io.IOException; import java.util.Locale; import java.util.ResourceBundle; public class MyCookiesForGet { private String url; private ResourceBundle bundle; @BeforeTest public void beforeTest(){ bundle = ResourceBundle.getBundle("application", Locale.CHINA); url = bundle.getString("test.url"); } @Test public void testGetCookies() throws IOException { String result; //从配置文件中拼接测试url String uri = bundle.getString("getCookees.uri"); String testUrl = this.url+uri; HttpGet get = new HttpGet(testUrl); HttpClient client = new DefaultHttpClient(); HttpResponse httpResponse= client.execute(get); result = EntityUtils.toString(httpResponse.getEntity()); System.out.println(result); } }
以上是关于配置文件application.properties剥离的主要内容,如果未能解决你的问题,请参考以下文章
我可以将内部 Spring Boot 变量传递给 gradlew 吗?
如何在 Cloud Foundry 使用 Spring Boot 外部化配置
未从 application.properties 中提取 Spring Boot JOOQ sql 方言