架构失败:"Child"不是定义的名称。"child"字段的类型必须是定义的名称或 { "type" : ...} 表达式



我在maven项目中有两个avro架构Parent.avsc和Child.avsc。我想从avsc文件生成Java类。我试图用mvn clean install来构建这个项目,但遇到了异常。能帮我找出问题吗?

{
"type" : "record",
"name" : "Parent",
"namespace" : "com.namespace",
"fields" : [
{"name" : "child", "type" : "Child", "doc"  : "Child doc" }
],
"doc" : "Parent doc"
}

儿童

{
"type" : "record",
"name" : "Child",
"namespace" : "com.namespace",
"fields" : [
{"name" : "child_id",    "type" : "string",                            "doc"  : "Id"},
{"name" : "child_name",  "type" : ["string", "null"], "default": null, "doc"  : "Name"}
],
"doc" : "Child"
}

Pom插件

<plugin>
<groupId>org.apache.avro</groupId>
<artifactId>avro-maven-plugin</artifactId>
<version>${avro.version}</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>schema</goal>
</goals>
<configuration>
<sourceDirectory>
${project.basedir}/src/main/avro/
</sourceDirectory>
<includes>
<include>**/*.avsc</include>
</includes>
<imports>
<import>${project.basedir}/src/main/avro/Parent.avsc</import>
<import>${project.basedir}/src/main/avro/Child.avsc</import>
</imports>
<stringType>String</stringType>
</configuration>
</execution>
</executions>
</plugin>

您需要在pom.xml中导入子对象,然后再导入其父对象:

<imports>
<import>${project.basedir}/src/main/avro/Child.avsc</import>
<import>${project.basedir}/src/main/avro/Parent.avsc</import>
</imports>

最新更新