最近幾個項目子產品要從hadoop1更新到hadoop2,不過在修改的過程中出現了一些問題,其中一個問題就是在使用 FileSystem fs = FileSystem.get(conf);調用hdfs時報錯,具體報錯資訊如下:
檢視FileSystem類發現通過FileSystem.get()初始化的時候,需要通過靜态加載的方式來實作,具體實作如下:
從代碼中可以看出最終需要調用getFileSystemClass(String scheme, Configuration conf)方法,在此方法中需要讀取core-default.xml檔案中定義的“fs.” + scheme + ".impl"(在本例中應讀取fs.hdfs.impl)的配置資訊,但此配置資訊在預設的配置檔案中沒有配置(hadoop-common-x.jar中的core-default.xml檔案中).
------------------------------------------
解決辦法:
在配置檔案core-default.xml中添加如下配置資訊:
<property>
<name>fs.hdfs.impl</name>
<value>org.apache.hadoop.hdfs.DistributedFileSystem</value>
<description>The FileSystem for hdfs: uris.</description>
</property>