配置文件application.properties剥离

1、在resources目录下配置application.properties:

test.url=http://127.0.0.1:8888
getCookees.uri=/getCookies
login=/login

application.properties

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);
    }
}

配置文件在测试代码中使用

原文地址:https://www.cnblogs.com/wangkc/p/10851217.html

时间: 2024-10-08 09:11:40

配置文件application.properties剥离的相关文章

Spring Boot之配置文件application.properties

Spring Boot默认的配置文件为application.properties,放在src/main/resources目录下或者类路径的/config目录下,作为Spring Boot的全局配置文件,对一些默认的配置进行修改. 接下来使用例子展示Spring Boot配置文件的用法: 首先在src/main/resources下新建application.properties文件,内容如下 author.name=微儿博客 author.sex=男 创建controller类 ackage

Spring Boot2 系列教程(四)理解Spring Boot 配置文件 application.properties

在 Spring Boot 中,配置文件有两种不同的格式,一个是 properties ,另一个是 yaml . 虽然 properties 文件比较常见,但是相对于 properties 而言,yaml 更加简洁明了,而且使用的场景也更多,很多开源项目都是使用 yaml 进行配置(例如 Hexo).除了简洁,yaml 还有另外一个特点,就是 yaml 中的数据是有序的,properties 中的数据是无序的,在一些需要路径匹配的配置中,顺序就显得尤为重要(例如我们在 Spring Cloud

spring boot配置文件application.properties配置JPA以及数据源

1.application.properties配置jpa模板 spring.datasource.url=jdbc:mysql://localhost:3306/springboottest?useUnicode=true&characterEncoding=utf8&serverTimezone=UTC spring.datasource.username=rootspring.datasource.password=Zp970321spring.datasource.driver-c

Spring Boot中配置文件application.properties里面配置项的引用

方法1:绑定对象bean调用 1.在application.properties或者application.yml里面添加我们的配置项: 2.创建一个配置类(该类和我们上面配置项的属性一一对应): import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; @Component @ConfigurationP

SpringBoot配置文件application.properties详解

相信很多的码友在接触springboot时,不知道怎么去配置一些项目中需要的配置,比如数据源,tomcat调优,端口等等,下面我就给大家奉献出一些项目中常用的配置信息. 如何偏差的地址欢迎大家来指正. 配置文件比较多,自己寻找所需要的,后面我会给大家推荐几个常用的配置文件. # = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

springboot配置文件application.properties

# =================================================================== # COMMON SPRING BOOT PROPERTIES # # This sample file is provided as a guideline. Do NOT copy it in its # entirety to your own application. ^^^ # ===================================

Spring boot配置文件application.properties

# =================================================================== # COMMON SPRING BOOT PROPERTIES # # This sample file is provided as a guideline. Do NOT copy it in its # entirety to your own application.               ^^^ # =====================

Spring boot配置文件 application.properties

# =================================================================== # COMMON SPRING BOOT PROPERTIES # # This sample file is provided as a guideline. Do NOT copy it in its # entirety to your own application.               ^^^ # =====================

附录B. Spring Boot 配置文件application.properties

#SPRING CONFIG (ConfigFileApplicationListener) spring.config.name= # config file name (default to 'application') spring.config.location= # location of config file #PROFILES spring.profiles= # comma list of active profiles #APPLICATION SETTINGS (Sprin