package com.imooc.flink.cdc
import com.ververica.cdc.connectors.mysql.MySqlSource
import com.ververica.cdc.connectors.mysql.table.StartupOptions
import com.ververica.cdc.debezium.{DebeziumSourceFunction, StringDebeziumDeserializationSchema}
import org.apache.flink.api.scala._
import org.apache.flink.streaming.api.scala.StreamExecutionEnvironment
object FlinkCDCDataStreamApp {
def main(args: Array[String]): Unit = {
val environment = StreamExecutionEnvironment.getExecutionEnvironment
environment.setParallelism(1)
val source: DebeziumSourceFunction[String] = MySqlSource.builder()
.hostname("localhost").port(3306)
.username("root").password("1997")
.databaseList("pk_cdc").tableList("user")
.startupOptions(StartupOptions.initial())
//设置反序列化
.deserializer(new StringDebeziumDeserializationSchema)
.build()
environment.addSource(source).print()
environment.execute("FlinkCDCDataStreamApp");
}
}
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/flink/shaded/guava18/com/google/common/collect/Maps
at com.ververica.cdc.connectors.mysql.MySqlValidator.<init>(MySqlValidator.java:50)
at com.ververica.cdc.connectors.mysql.MySqlSource$Builder.build(MySqlSource.java:230)
at com.imooc.flink.cdc.FlinkCDCDataStreamApp$.main(FlinkCDCDataStreamApp.scala:20)
at com.imooc.flink.cdc.FlinkCDCDataStreamApp.main(FlinkCDCDataStreamApp.scala)
Caused by: java.lang.ClassNotFoundException: org.apache.flink.shaded.guava18.com.google.common.collect.Maps
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
... 4 more
Process finished with exit code 1
Scala用了2.11和2.12的都试了
登录后可查看更多问答,登录/注册
已经在做大数据,Flink助力轻松提薪;尚未入行,让你弯道超车
了解课程