• 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;
        }
    
    }
  • 相关阅读:
    JAVA 基础
    【爬虫】爬取豆瓣图书TOP250
    error: src refspec master does not match any. error: failed to push some refs to 'git@github.com:xxx/xxx.git'
    el-upload如何做到在添加文件时限制文件类型
    :last-child无法选中父元素中最后一个元素
    桥接模式-图形界面配置centos7的ip
    tomcat输出日志乱码
    精简步骤 Centos7命令行安装Tomcat、配置tomcat端口及配置防火墙开放端口
    命令行设置远程访问mysql
    No archetype found in remote catalog. Defaulting to internal catalog
  • 原文地址:https://www.cnblogs.com/xianz666/p/13403243.html
Copyright © 2020-2023  润新知