Spring 如何在Hadoop中加载外部属性文件

Spring 如何在Hadoop中加载外部属性文件,spring,hadoop,configuration-files,Spring,Hadoop,Configuration Files,我有一份hadoop的工作,其中包括一些SpringBean。此外,在spring上下文文件中,还有一个名为app.properties的PropertyPlaceHolderConfigure 这个app.properties在jar文件中,其想法是将其从jar文件中删除,以便在不重新编译的情况下更改某些属性 我尝试了-file选项和-jarlibs选项,但都不起作用 有什么想法吗?您可以将此属性文件添加到分布式缓存中,如下所示: ... String s3PropertiesFilePath

我有一份hadoop的工作,其中包括一些SpringBean。此外,在spring上下文文件中,还有一个名为app.properties的PropertyPlaceHolderConfigure

这个app.properties在jar文件中,其想法是将其从jar文件中删除,以便在不重新编译的情况下更改某些属性

我尝试了
-file
选项和
-jarlibs
选项,但都不起作用


有什么想法吗?

您可以将此属性文件添加到分布式缓存中,如下所示:

...
String s3PropertiesFilePath = args[0];
DistributedCache.addCacheFile(new URI(s3PropertiesFilePath), conf);
...
稍后,在mapper/reducer的configure()中,可以执行以下操作:

...
Path s3PropertiesFilePath;
Properties prop = new Properties();
@Override
public void configure(JobConf job) {
    s3PropertiesFilePath = DistributedCache.getLocalCacheFiles(job)[0];
    //load the properties file
    prop.load(new FileInputStream(s3PropertiesFilePath.toString()));
...
}

PS:如果您没有在Amazon EMR上运行它,那么您可以将此属性文件保留在hdfs中,并提供该路径。

您可以将此属性文件添加到分布式缓存中,如下所示:

...
String s3PropertiesFilePath = args[0];
DistributedCache.addCacheFile(new URI(s3PropertiesFilePath), conf);
...
稍后,在mapper/reducer的configure()中,可以执行以下操作:

...
Path s3PropertiesFilePath;
Properties prop = new Properties();
@Override
public void configure(JobConf job) {
    s3PropertiesFilePath = DistributedCache.getLocalCacheFiles(job)[0];
    //load the properties file
    prop.load(new FileInputStream(s3PropertiesFilePath.toString()));
...
}
PS:如果您没有在Amazon EMR上运行它,那么您可以将此属性文件保存在hdfs中,并提供该路径。

我所做的是:

  • 子类化PropertyPlaceHolderConfigure
  • 重写loadProperties方法
  • 如果有自定义System.getProperty(“hdfs_路径”)

工作起来很有魅力…

我所做的是:

  • 子类化PropertyPlaceHolderConfigure
  • 重写loadProperties方法
  • 如果有自定义System.getProperty(“hdfs_路径”)


工作起来很有魅力…

这很好,但我需要更换app.properties。使用这种方法,我仍然需要创建一个自定义PropertyPlaceHolder,以便在两个app.properties(外部|内部)之间切换。无论如何,非常感谢。这很好,但我需要更换app.properties源文件。使用这种方法,我仍然需要创建一个自定义PropertyPlaceHolder,以便在两个app.properties(外部|内部)之间切换。无论如何,非常感谢。