提交 f6e24ab6 编写于 作者: A Aljoscha Krettek

[FLINK-8186] Exclude flink-avro from flink-dist; fix AvroUtils loading

Before, AvroUtils were loaded when the class was loaded which didn't
take into account the user-code ClassLoader. Now, we try loading avro
utils with the Thread context ClassLoader.
上级 dd48a40a
......@@ -37,12 +37,14 @@ public abstract class AvroUtils {
private static final String AVRO_KRYO_UTILS = "org.apache.flink.formats.avro.utils.AvroKryoSerializerUtils";
private static final AvroUtils INSTANCE = loadAvroKryoUtils();
private static AvroUtils loadAvroKryoUtils() {
/**
* Returns either the default {@link AvroUtils} which throw an exception in cases where Avro
* would be needed or loads the specific utils for Avro from flink-avro.
*/
public static AvroUtils getAvroUtils() {
// try and load the special AvroUtils from the flink-avro package
try {
Class<?> clazz = Class.forName(AVRO_KRYO_UTILS, false, AvroUtils.class.getClassLoader());
Class<?> clazz = Class.forName(AVRO_KRYO_UTILS, false, Thread.currentThread().getContextClassLoader());
return clazz.asSubclass(AvroUtils.class).getConstructor().newInstance();
} catch (ClassNotFoundException e) {
// cannot find the utils, return the default implementation
......@@ -52,14 +54,6 @@ public abstract class AvroUtils {
}
}
/**
* Returns either the default {@link AvroUtils} which throw an exception in cases where Avro
* would be needed or loads the specific utils for Avro from flink-avro.
*/
public static AvroUtils getAvroUtils() {
return INSTANCE;
}
// ------------------------------------------------------------------------
/**
......
......@@ -79,12 +79,6 @@ under the License.
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-avro</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-streaming-java_${scala.binary.version}</artifactId>
......@@ -492,10 +486,6 @@ under the License.
</excludes>
</artifactSet>
<relocations>
<relocation>
<pattern>org.codehaus.jackson</pattern>
<shadedPattern>org.apache.flink.formats.avro.shaded.org.codehaus.jackson</shadedPattern>
</relocation>
<relocation>
<!-- relocate jackson services, which isn't done by flink-shaded-jackson -->
<pattern>com.fasterxml.jackson</pattern>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册