1,因本地依赖的包和服务器上包冲突。主要是是flink集群已经有guava的jar包。错误代码如下:
2020-12-04 23:35:45
java.lang.NoSuchMethodError: com.google.common.hash.Hashing.farmHashFingerprint64()Lcom/google/common/hash/HashFunction;
at com.dewu.com.aliyun.openservices.aliyun.log.producer.internals.Utils.generateProducerHash(Utils.java:31)
at com.dewu.com.aliyun.openservices.aliyun.log.producer.LogProducer.<init>(LogProducer.java:91)
at com.poizon.userportrait.sink.redis.UserPortraitRedisSink.open(UserPortraitRedisSink.java:123)
at com.alibaba.blink.streaming.connector.custom.sink.CustomOutputFormat.open(CustomOutputFormat.java:70)
at com.alibaba.blink.streaming.connectors.common.output.TupleOutputFormatAdapterSink.open(TupleOutputFormatAdapterSink.java:51)
at org.apache.flink.api.common.functions.util.FunctionUtils.openFunction(FunctionUtils.java:36)
at org.apache.flink.streaming.api.operators.AbstractUdfStreamOperator.open(AbstractUdfStreamOperator.java:102)
at org.apache.flink.streaming.api.operators.StreamSink.open(StreamSink.java:48)
at org.apache.flink.streaming.runtime.tasks.StreamTask.openAllOperators(StreamTask.java:527)
at org.apache.flink.streaming.runtime.tasks.StreamTask.lambda$invoke$1(StreamTask.java:386)
at org.apache.flink.util.checkpointlock.SynchronizedLockHelper.lockAndRun(SynchronizedLockHelper.java:51)
at org.apache.flink.util.checkpointlock.CheckpointLockDelegate.lockAndRun(CheckpointLockDelegate.java:52)
at org.apache.flink.streaming.runtime.tasks.StreamTask.invoke(StreamTask.java:380)
at org.apache.flink.runtime.taskmanager.Task.run(Task.java:736)
at java.lang.Thread.run(Thread.java:834)
2,通过maven的插件,relocation重定义类目即可解决问题。maven配置如下:
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<relocations>
<relocation>
<pattern>com.aliyun.openservices.aliyun.log.producer</pattern>
<shadedPattern>com.xxxx.com.aliyun.openservices.aliyun.log.producer</shadedPattern>
</relocation>
<relocation>
<pattern>com.google.common</pattern>
<shadedPattern>com.xxxx.com.google.common</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
或者其他方式
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<relocations>
<relocation>
<pattern>net.jpountz.lz4</pattern>
<shadedPattern>com.vipshop.net.jpountz.lz4</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
</plugin>
3,注意,上传jar的时候,不能使用带dependencies.jar的包,就用原生的即可
参考从定向类