zoukankan      html  css  js  c++  java
  • bladex从blade-dev.yaml 读取配置信息

    blade-dev.yaml配置======nacos文件配置
    #sap配置
    sap:
      api:
        read:
          url: http://read.xxxxxxxx.com.cn
          port: 80
          username: admin
          password: xxxxx
        write:
          url: http://write.xxxxxxx.com.cn
          port: 80
          username: admin
          password: xxxxx
    
    appliction-dev.yaml配置======= 使用的微服务模块
    #服务器端口
    server:
      port: 8105
    
    #数据源配置
    spring:
      datasource:
        url: ${blade.datasource.dev.url}
        username: ${blade.datasource.dev.username}
        password: ${blade.datasource.dev.password}
    #sap配置
    sap:
      api:
        read:
          url: ${sap.api.read.url}
          port: ${sap.api.read.port}
          username: ${sap.api.read.username}
          password: ${sap.api.read.password}
        write:
          url: ${sap.api.write.url}
          port: ${sap.api.write.port}
          username: ${sap.api.write.username}
          password: ${sap.api.write.password}
    
    util类
    @Component
    public class SapUtil {
        public static String readUrl ;
        public static String readPort ;
        public static String readUsername ;
        public static String readPassword;
        public static String writeUrl ;
        public static String writePort ;
        public static String writeUsername ;
        public static String writePassword;
    
        @Value("${sap.api.read.url}")
        public void setReadUrl(String readUrl){
            SapUtil.readUrl = readUrl;
        }
        @Value("${sap.api.read.port}")
        private void setReadPort(String readPort){
            SapUtil.readPort = readPort;
        }
        @Value("${sap.api.read.username}")
        public void setReadUsername(String readUsername) {
            SapUtil.readUsername = readUsername;
        }
        @Value("${sap.api.read.password}")
        public void setReadPassword(String readPassword) {
            SapUtil.readPassword = readPassword;
        }
        @Value("${sap.api.write.url}")
        public void setWriteUrl(String writeUrl) {
            SapUtil.writeUrl = writeUrl;
        }
        @Value("${sap.api.write.port}")
        public void setWritePort(String writePort) {
            SapUtil.writePort = writePort;
        }
        @Value("${sap.api.write.username}")
        public void setWriteUsername(String writeUsername) {
            SapUtil.writeUsername = writeUsername;
        }
        @Value("${sap.api.write.password}")
        public void setWritePassword(String writePassword) {
            SapUtil.writePassword = writePassword;
        }
    
        private static String readToken = "";
        private static long readCreateDate = 0l;
    
        private static String writeToken ="";
        private static long writeCreateDate = 0l ;
    
        public static String getReadToken(){
            if("".equals(readToken) || Func.isEmpty(readToken) || Func.isNull(readToken)){
                return getToken(readUsername,readPassword);
            }
            else{
                if(DateUtil.now().getTime() - readCreateDate >= 43000000l ){
                    return getToken(readUsername,readPassword);
                }
            }
            return readToken;
        }
    
        public static String getWriteToken(){
            if("".equals(writeToken) || Func.isEmpty(writeToken) || Func.isNull(writeToken)){
                return getToken(writeUsername,writePassword);
            }
            else{
                if(DateUtil.now().getTime() - writeCreateDate >= 43000000l ){
                    return getToken(writeUsername,writePassword);
                }
            }
            return writeToken;
        }
    
        public static String getToken(String username,String password){
            Authorize auth = new Authorize();
            auth.setUsername(username);
            auth.setPassword(password);
            try {
                String res = HttpUtil.doJsonPost(SapConstant.LOGIN_AUTHORIZE, JSONObject.toJSONString(auth),null);
                if(!Func.isEmpty(res)&&!Func.isNull(res)){
                    Token token = JSONObject.parseObject(res, Token.class);
                    readToken=token.getToken();
                    readCreateDate = DateUtil.now().getTime();
                }
            }
            catch(Exception e){
                // TODO
            }
            return readToken;
        }
    
    }
  • 相关阅读:
    GISer面对创业的困惑
    近期微博吐槽言论存档,涉及“性能优化”、C++陋习等
    HDU 2825 Wireless Password【AC自动机+DP】
    20130809, 微软八月安全补丁提前通知
    终于把3DMAX的MSE搞定了!
    UVA 11464 Even Parity (独特思路)
    [置顶] hdu 4418 高斯消元解方程求期望
    UVA 10652 Board Wrapping
    少儿编程-教育:少儿编程教育
    少儿编程:目录
  • 原文地址:https://www.cnblogs.com/xianz666/p/13403243.html
Copyright © 2011-2022 走看看