zoukankan      html  css  js  c++  java
  • 接口自动化增加环境隔离功能

    1. pom文件设置: 

    在build节点下增加:

    <resources>
          <resource>
            <!-- 指定配置文件所在的目录,${deploy.type}是一个参数变量,通过这个变量来决定加载哪个环境的配置文件 -->
            <directory>src/main/resources.${deploy.type}</directory>
            <!-- 排除.jsp文件,也就是不加载.jsp文件 -->
            <excludes>
              <exclude>*.jsp</exclude>
            </excludes>
          </resource>
          <resource>
            <directory>src/main/resources</directory>
          </resource>
        </resources>

    插入新节点:

    <profiles>
        <!-- 测试环境 -->
        <profile>
          <id>uat</id>
          <activation>
            <!-- 表示如果编译时没有指定环境,则以该环境为默认环境 -->
            <activeByDefault>true</activeByDefault>
          </activation>
          <properties>
            <deploy.type>uat</deploy.type>
          </properties>
        </profile>
    
        <!-- 生产环境 -->
        <profile>
          <id>prod</id>
          <properties>
            <deploy.type>prod</deploy.type>
          </properties>
        </profile>
      </profiles>

    2.  数据源:在main目录下新建两个文件夹

    在两个文件夹下,分别创建一个名为 datasource.properties 的文件

     3. 读取properties数据的util方法

    private static Properties properties;
    
    /*
         *从datasource中取数据
         */
        public String getValue(String key) throws IOException {
            String propertiesFileName = "datasource.properties";
            InputStream stream = this.getClass().getClassLoader().getResourceAsStream(propertiesFileName);
            properties = new Properties();
            properties.load(stream);
            String value = properties.getProperty(key);
            return value;
        }
  • 相关阅读:
    关于java的scanner类
    switch_case注意事项
    MySQL数据库语句总结
    注册验证
    简单的java水果商店后台
    easyui判断下拉列表
    springmvc的前端控制器
    springmvc注解驱动
    双色球
    初来乍到
  • 原文地址:https://www.cnblogs.com/zqlmmd/p/12074623.html
Copyright © 2011-2022 走看看