我能够使用以下代码解决此问题:
Java 代码:
Configuration hadoopConfiguration = SparkSession.sparkContext().hadoopConfiguration();
log.info("CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH : "+hadoopConfiguration.get(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH ));
String accessKey = new String(hadoopConfiguration.getPassword("fs.s3a.access.key"));
String secretKey = new String(hadoopConfiguration.getPassword("fs.s3a.secret.key"));
斯卡拉代码:
val hadoopConfiguration = sparkSession.sparkContext.hadoopConfiguration
hadoopConfiguration.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, keyFileHdfsPath);
val access_Key = hadoopConfiguration.getPassword("fs.s3a.access.key").mkString
val secret_Key = hadoopConfiguration.getPassword("fs.s3a.secret.key").mkString