• SpringBoot项目接入Jco调用SAP接口遇到的问题


    SpringBoot项目接入Jco调用SAP接口遇到的问题

    1.1 It is not allowed to rename or repackage the original archive "sapjco3.jar".

    由于jar包是下载到本地的,所以将 jar包添加到本地仓库。再在项目中引用。

    maven命令:

    mvn install:install-file -Dfile=D:sapjco3.jar -DgroupId=sapjco3 -D artifactId=sapjco3 -Dversion=1.0 -Dpackaging=jar
    

    pom.xml中添加引用

            <!--sap jco-->
            <dependency>
                <groupId>sapjco3</groupId> 
                <artifactId>sapjco3</artifactId> 
                <version>IDE</version>
            </dependency>
    

    项目打包时,会生成sapjco3-IDE.jar包,这个包名会引发Jco的异常。

    Illegal JCo archive "sapjco3-IDE.jar". 
    It is not allowed to rename or repackage the original archive "sapjco3.jar".
    

    项目打包后,需要手动将项目包中的sapjco3-IDE.jar重命名为sapjco3.jar,然后重新启动项目即可。

    1.2更新解决办法:

    1.将sapjco3.jar安装到本地maven仓库与服务器中。

    2.项目中使用本地仓库的引用

    3.在pom文件中配置,在项目打包时,过滤sapjco3.jar,不将其打包到最后的包中
    4.把sapjco3.jar拷贝到服务器上,更新服务器的环境变量,classPath中添加sapjco3.jar

    5.正常启动项目即可。

    优点:一劳永逸,不需要每次更新包时,去手动修改包名;

    缺点:一劳;

    2.DestinationDataProvider already registered

    注册过DestinationDataProvider后,使用结束,需要手动释放,否则再次调用方法会报异常。

    void test(){
        try{
            ···
            Environment.registerDestinationDataProvider(myDataProvider);        
            ···
        }catch(Exception ex){
            log.info(ex.getMessage());
        }finally{
            Environment.unregisterDestinationDataProvider(myDataProvider);
        }
    }
    
    

    3.call function

    方法调用操作顺序: 1.设置入参 -> 2.执行方法 -> 3.获取返回结果

    JCoFunction function =  destination.getRepository().getFunction("your function name");
    
    0.数据类型

    sap数据类型一共有三种

    字段 / 结构(Structure) / 表(Table)
    
    1.入参

    在调用function之前,可以修改function的入参。

    // 字段类型的入参
    JCoParameterList inputParameterList = function.getImportParameterList();
    inputParameterList.setValue("param_name","value");
    
    // table类型的入参
    JCoParameterList tableParameterList = function.getTableParameterList();
    JCoTable jCoTable = tableParameterList.getTable("table_param_name");
    jCoTable.appendRow(); // 添加行
    jCoTable.setValue("columnName", "value");
    
    // 执行方法
    function.execute(destination);
    
    ···
    
    2.出参
    ···
    // 执行方法
    function.execute(destination);
    // 字段类型的出参
    String feildResult = function.getExportParameterList().getString("fieldName");
    
    // table类型的出餐
    JCoTable result_table = function.getTableParameterList().getTable("result_table_name");
    
    for (int i = 0; i < result_table.getNumRows(); i++, result_table.nextRow()) {
        result_table.setRow(i); // 打开行数据
        result_table.getString("columnName"); // 获取对应列的值
        ···
    }
    
  • 相关阅读:
    在 centos 下禁止 root 通过 ssh 远程登录
    在 sql server 中开启审核日志
    设置 centos 系统,使用终端连接的空闲等待时间(超时断开)
    谷歌地图文字渲染原理
    WebGL 水波及焦散(刻蚀)的渲染总结
    【Mybatis】获取sql
    git如何查看最新的远程分支
    绑定点击事件,当点击事件里依赖异步返回结果则阻止冒泡失效
    一个非常好用的生成目录树的npm包
    Spring Boot入门系列(二十一)如何优雅的设计 Restful API 接口版本号,实现 API 版本控制!
  • 原文地址:https://www.cnblogs.com/mlocvery/p/12706367.html
Copyright © 2020-2023  润新知