无法设置属性setProperty

时间:2019-07-19 03:28:23

标签: java properties

我遇到了非常奇怪的情况。不确定,是否符合逻辑,但是请打扰。

我有两个元素,一个是 jar文件 ,第二个是 ETL工具 基于Java的高级ETL工具。

我已经将jar导入了一个ETL的工作中。 jar中发生的事情是,当我从JSON加载太多参数时,我可以在ETL代码中使用它们。这些参数是使用属性方法setProperty设置的,我可以使用getProperty来访问所有ETL代码。

但是jar中只有一个类,如下所示:

public class SetRecordCount {

    static String count;

    public void execute(Properties context) {
      context.setProperty("Count",context.getProperty("RecordCount")); // not accessible
      count = context.getProperty("RecordCount"); // Here accessible
    }
}

我无法在ETL中访问context.getProperty("Count"),并且它返回null。但是为什么将其设为null,因为我只能以这种方式(context.setProperty)设置所有传入JSON的参数,并且能够在ETL中访问它们。 (注意:我正在使用相同的Properties实例(上下文)来加载参数)

但是,如果我将计数值设置为类的成员,那么我可以使用SetRecordCount.count

在我的ETL代码中获取该值。

这很奇怪吗??

任何人都可以分享使用 context.setProperty("Count",context.getProperty("RecordCount"))来获取价值的错误做法吗?

1 个答案:

答案 0 :(得分:0)

尝试执行此操作:

// First, retrieve count and then set that in context.
count = context.getProperty("RecordCount");
context.setProperty("Count", count); 
相关问题