在我的spark作业中传递外部yml文件/代码不工作抛出“;Can';t为标签构建java对象:yaml.org,2002“;
我使用的是spark 2.4.1版本和java8。我尝试在使用spark submit提交spark作业时加载外部属性文件 因为我正在使用下面的TypeSafe加载我的属性文件在我的spark作业中传递外部yml文件/代码不工作抛出“;Can';t为标签构建java对象:yaml.org,2002“;,yaml,databricks,snakeyaml,typesafe,typesafe-config,Yaml,Databricks,Snakeyaml,Typesafe,Typesafe Config,我使用的是spark 2.4.1版本和java8。我尝试在使用spark submit提交spark作业时加载外部属性文件 因为我正在使用下面的TypeSafe加载我的属性文件 <groupId>com.typesafe</groupId> <artifactId>config</artifactId> <version>1.3.1</version> 我的spark工作脚本是 我做错了什么?如何解决这个问题? 任何修复都
<groupId>com.typesafe</groupId>
<artifactId>config</artifactId>
<version>1.3.1</version>
我的spark工作脚本是
我做错了什么?如何解决这个问题?
任何修复都是非常感谢的
测试:
19/09/18 04:40:33 ERROR yml.InputYamlProcessor: e1 Name :tab1
Can't construct a java object for tag:yaml.org,2002:com.snp.helpers.QueryEntities; exception=Class not found: com.snp.helpers.QueryEntities
in 'reader', line 1, column 1:
entitiesList:
at org.yaml.snakeyaml.constructor.Constructor$ConstructYamlObject.construct(Constructor.java:345)
我在课堂上打印了这样的东西,在上面的那行之前。。。检查问题是否确实存在,但未找到类
public static void printTest() {
QueryEntity e1 = new QueryEntity();
e1.setTableName("tab1");
List<QueryEntity> li = new ArrayList<QueryEntity>();
li.add(e1);
QueryEntities ll = new QueryEntities();
ll.setEntitiesList(li);
ll.getEntitiesList().stream().forEach(e -> logger.error("e1 Name :" + e.getTableName()));
return;
}
这里出了什么问题?这与质疑无关 i、 e.YAMLException:未找到类:com.snp.yml.QueryEntities YML构造函数是否存在问题 改为
Yaml yaml = new Yaml(new CustomClassLoaderConstructor(com.snp.helpers.QueryEntities.class.getClassLoader()));
从
“找不到类”通常是一个错误,当类加载器请求加载某个类时,该类无法找到。我对spark不太熟悉,但是您确定
ca-datamigration-0.0.1.jar
中包含这个类吗?你能解压并检查它吗?你能做jar-tf ca-datamigration-0.0.1.jar | grep-i QueryEntities
并查看文件是否包含在内吗?另外,请检查--jars”/local/jars/*.jar“
中的jar。请确定您的构建系统并包括完整的构建配置将错误“exception=Class not found:com.snp.yml.QueryEntities”与[ca datamigration]$jar-tf ca-datamigration-0.0.1.jar | grep-i QueryEntities com/yml/QueryEntities.Class
进行比较。你能看出区别吗?提示:包不匹配。您是如何“移动”类的?它应该是将应用程序类捆绑在一起的构建过程的一部分。
public static void printTest() {
QueryEntity e1 = new QueryEntity();
e1.setTableName("tab1");
List<QueryEntity> li = new ArrayList<QueryEntity>();
li.add(e1);
QueryEntities ll = new QueryEntities();
ll.setEntitiesList(li);
ll.getEntitiesList().stream().forEach(e -> logger.error("e1 Name :" + e.getTableName()));
return;
}
19/09/18 04:40:33 ERROR yml.InputYamlProcessor: e1 Name :tab1
Can't construct a java object for tag:yaml.org,2002:com.snp.helpers.QueryEntities; exception=Class not found: com.snp.helpers.QueryEntities
in 'reader', line 1, column 1:
entitiesList:
at org.yaml.snakeyaml.constructor.Constructor$ConstructYamlObject.construct(Constructor.java:345)
Yaml yaml = new Yaml(new CustomClassLoaderConstructor(com.snp.helpers.QueryEntities.class.getClassLoader()));
/*Constructor constructor = new Constructor(com.snp.helpers.QueryEntities.class);
Yaml yaml = new Yaml( constructor );*/