日本熟妇hd丰满老熟妇,中文字幕一区二区三区在线不卡 ,亚洲成片在线观看,免费女同在线一区二区

新增功能開關

一個業務通常由多個系統、多個功能模塊組成,為保證某些業務的動態性,后端程序通常會用開關來控制程序的邏輯,以達到在系統運行時切換運行邏輯的目的。本文介紹如何新增功能開關。

前提條件

您已接入新應用,詳情請參見使用SDK接入使用Spring Boot Starter接入

通過Java SDK接入

通過Java SDK接入的應用請參見以下步驟新增功能開關。

  1. 定義功能開關。

    在字段上加上 com.taobao.csp.switchcenter.annotation.AppSwitch 注解,字段修飾符必須為 public static

    例如以下代碼:

    public class CommonTypeSwitch {
    
        @AppSwitch(des = "String 類型開關", level = Level.p2)
        public static String stringSwitch = "string";
    
        @AppSwitch(des = "Integer 類型開關", level = Level.p1)
        public static Integer integerSwitch = 2;
    
        @AppSwitch(des = "Boolean 類型開關", level = Level.p4)
        public static Boolean booleanSwitch = true;
    
        @AppSwitch(des = "AtomicInteger 類型開關", level = Level.p1)
        public static AtomicInteger atomicIntegerSwitch = new AtomicInteger(21);
    
        @AppSwitch(des = "AtomicBoolean 類型開關", level = Level.p1)
        public static AtomicBoolean atomicBooleanSwitch = new AtomicBoolean(true);
    
        @AppSwitch(des = "AtomicLong 類型開關", level = Level.p1)
        public static AtomicLong atomicLongSwitch = new AtomicLong(4L);
    
        @AppSwitch(des = "泛型為 String List 類型開關", level = Level.p1)
        public static List<String> stringListSwitch = new ArrayList<String>();
    
        @AppSwitch(des = "泛型是<Integer, String> Map 開關", level = Level.p4)
        public static Map<Integer, String> INT_STRING_MAP = new HashMap<Integer, String>();
    
        @SuppressWarnings("deprecation")
        @AppSwitch(des = "Date類型開關", level = Level.p1)
        public static Date dateTypeSwitch = new Date(114, 6, 3);
    
        @AppSwitch(des = "BigInteger類型開關", level = Level.p1)
        public static BigInteger bigIntegerTypeSwitch = BigInteger.valueOf(38888);
    
        @AppSwitch(des = "BigDecimal類型開關", level = Level.p1)
        public static BigDecimal bigDecimalTypeSwitch = BigDecimal.valueOf(3.00000000001);
    
        @AppSwitch(des = "枚舉類型開關", level = Level.p1)
        public static EnumType enumTypeSwitch = EnumType.ITEM1;
    
        @AppSwitch(des = "泛型為List<Integer>的LinkedList", level = Level.p1)
        public static List<List<Integer>> LIST_INT_LINKEDLIST = new LinkedList<List<Integer>>();
    
        @AppSwitch(des = "泛型為<Map<String, Integer>, Map<String, Integer>>的HashMap", level = Level.p1)
        public static Map<Integer, Map<String, Map<String, Integer>>> MAP_MAP_HASHMAP = new HashMap<Integer, Map<String, Map<String, Integer>>>();
    }
  2. 調用注冊方法進行注冊。
    /*
     應用調用此方法完成注冊, 同時請保證應用在啟動的時候, 調用過且知道用過一次此方法,多次調用會拋出異常。
     應用名稱可不填,不填取 project.name 啟動參數的值其中,常量類參數是可變參數,可注冊多個常量類。
     如常量類未添加 com.taobao.csp.switchcenter.annotation.NameSpace 注解,默認使用完整類路徑名作為 namespace。
    */
    SwitchManager.init("appName", CommonTypeSwitch.class);
  3. 配置啟動參數。
    • 非公網
      //將 AppName 替換為自定義的應用名稱。
      ahas.namespace=default
      project.name=AppName
    • 公網
      //將AppName替換為自定義的應用名稱,將<license>替換為真實值。
      ahas.namespace=default
      project.name=AppName
      ahas.license=<license>
      說明 僅公網環境接入需要 License,您可在新應用接入頁面查看并保存 License,詳情請參見查看并保存 license
  4. 重新部署您的應用。

通過Spring Boot接入

通過Spring Boot接入的應用請參見以下步驟新增功能開關。

  1. 定義功能開關。
    • 在相關開關類上加上@Switch注解。
    • 在相關常量類上加com.alibaba.csp.ahas.switchcenter.anotation.Switch注解,同時在對應字段上加com.taobao.csp.switchcenter.annotation.AppSwitch注解,字段修飾符必須為public static
    @Switch
    public class SwitchConfig {
    
        @AppSwitch(des="Boolean 類型開關", level=Level.p2, callback=TestCallback.class)
        public static boolean test_switch = false;
    }
  2. 配置啟動參數。

    在application.properties中添加以下配置項。

    • 非公網
      #指定您要接入的特定的AHAS環境。
      ahas.namespace=default
      #自定義您的應用名稱。
      project.name=AppName
    • 公網
      #指定您要接入的特定的AHAS環境。
      ahas.namespace=default
      #自定義您的應用名稱。
      project.name=AppName
      #配置License信息。
      ahas.license=<license>
      說明 僅公網環境接入需要License,您可在新應用接入頁面查看并保存License,詳情請參見查看并保存 license
  3. 重新啟動您的應用。

執行結果

添加完成后,在功能開關頁面單擊目標應用的資源卡片,進入目標應用的開關列表頁面,可查看到新增開關的相關信息。

add_swtich

更多信息

如果您需要自定義功能開關的分組,可在代碼中添加com.taobao.csp.switchcenter.annotation.NameSpace 注解;如果沒有自定義,分組類別默認取class后面的類名,請參見以下示例。

package com.taobao.csp.switchcenter.example;

import com.taobao.csp.switchcenter.annotation.AppSwitch;
import com.taobao.csp.switchcenter.annotation.NameSpace;
import com.taobao.csp.switchcenter.bean.Switch.Level;

  @NameSpace(nameSpace="customNamespace") //customNamespace為自定義分組名。
  public class PrimitiveTypeSwitch     //PrimitiveTypeSwitch為默認分組名。
 {  
  @AppSwitch(des="int 類型開關", level=Level.p1)
  public static int primitiveIntSwitch=1;

  @AppSwitch(des="doubel 類型開關", level=Level.p1)
  public static double primitiveDoubleSwitch=1.121;
 }
說明 其中com.taobao.csp.switchcenter.bean.Switch.Level指開關的重要程度,分為p1、p2、p3、p4四個檔位,p1的重要程度最高,p4的重要程度最低。