spring-attic / cdc-debezium

Change Data Capture (CDC) source that captures and streams change events from various databases. Leverages on Debezium and supports MySQL, PostgreSQL, MongoDB, Oracle and SQL Server databases.
Apache License 2.0
52 stars 15 forks source link

NoClassDefFoundError: com.mysql.cj.jdbc.Driver error due to using mysql 5.1.XX version #4

Closed enkeebbx closed 5 years ago

enkeebbx commented 5 years ago

The required mysql version for this project based on its documentation is 5.1.XX, but the project tries to find com.mysql.cj.jdbc.Driver and fails upon run. This error calls for inspection.

@spring-operator @sobychacko @tzolov

sabbyanandan commented 5 years ago

Hi, @enkeebbx. Could you update the description with what version is in use, error stacktrace, and the details on how you're attempting to run it?

enkeebbx commented 5 years ago

Sure, @sabbyanandan!

I followed this quick start tutorial https://github.com/tzolov/cdc-debezium/blob/master/spring-cloud-starter-stream-common-cdc-debezium/cdc-debezium-spring-boot-starter/README.adoc and added the following dependencies to my pom.xml.

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud.stream.app</groupId>
            <artifactId>cdc-debezium-spring-boot-starter</artifactId>
            <version>2.1.1.BUILD-SNAPSHOT</version>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.46</version>
        </dependency>
    </dependencies>

However, upon mvn spring-boot run, I got :

Unable to initialize and start connector's task class 'io.debezium.connector.mysql.MySqlConnectorTask' with config: {name=my-sql-connector, offset.commit.policy=io.debezium.embedded.spi.OffsetCommitPolicy$PeriodicCommitOffsetPolicy, connector.class=io.debezium.connector.mysql.MySqlConnector, database.server.id=85744, database.port=3306, offset.storage=org.springframework.cloud.stream.app.cdc.common.core.store.MetadataStoreOffsetBackingStore, database.user=****, database.hostname=*****, database.password=********, database.history=io.debezium.relational.history.MemoryDatabaseHistory, offset.flush.interval.ms=60000, database.server.name=my-app-connector, offset.flush.timeout.ms=5000}

java.lang.NoClassDefFoundError: com/mysql/cj/jdbc/Driver
    at io.debezium.connector.mysql.MySqlConnectorConfig.<clinit>(MySqlConnectorConfig.java:695) ~[debezium-connector-mysql-0.9.2.Final.jar:0.9.2.Final]
    at io.debezium.connector.mysql.MySqlConnectorTask.getAllConfigurationFields(MySqlConnectorTask.java:444) ~[debezium-connector-mysql-0.9.2.Final.jar:0.9.2.Final]
    at io.debezium.connector.common.BaseSourceTask.start(BaseSourceTask.java:38) ~[debezium-core-0.9.2.Final.jar:0.9.2.Final]
    at org.springframework.cloud.stream.app.cdc.common.core.EmbeddedEngine.run(EmbeddedEngine.java:804) ~[spring-cloud-starter-stream-common-cdc-debezium-core-2.1.1.BUILD-SNAPSHOT.jar:2.1.1.BUILD-SNAPSHOT]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) ~[na:1.8.0_171]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) ~[na:1.8.0_171]
    at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_171]
Caused by: java.lang.ClassNotFoundException: com.mysql.cj.jdbc.Driver
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_171]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_171]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_171]
    ... 7 common frames omitted

Here is my application.properties that I wrote accordingly:

cdc.name=my-sql-connector
cdc.connector=mysql

cdc.config.name=my-sql-connector
cdc.config.database.history=io.debezium.relational.history.MemoryDatabaseHistory
cdc.config.database.server.id=85744
cdc.config.database.server.name=my-app-connector
cdc.config.database.user=****
cdc.config.database.password=****
cdc.config.database.hostname=****
cdc.config.database.port=3306

cdc.schema=false

cdc.flattering.enabled=true
sabbyanandan commented 5 years ago

Thanks for the update, @enkeebbx. We will review it.

tzolov commented 5 years ago

Hi @enkeebbx , finally i got time to check this. It appears that the problem is due to to wrong versions for both dc-debezium-spring-boot-starter and the mysql-connector-java. Here are the correct versions that work form me:

        <dependency>
            <groupId>org.springframework.cloud.stream.app</groupId>
            <artifactId>cdc-debezium-spring-boot-starter</artifactId>
            <version>1.0.0.BUILD-SNAPSHOT</version>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.13</version>
        </dependency>

E.g. 1.0.0.BUILD-SNAPSHOT for the starter (the 1.0.0.M1 might work as well) and 8.0.13 for the mysql-connector. I've updated the poms and docs: https://github.com/spring-cloud-stream-app-starters/cdc-debezium/tree/master/spring-cloud-starter-stream-common-cdc-debezium/cdc-debezium-spring-boot-starter

Also unless you are compiling it locally you may want to add the Spring snapshot (and or milestone) maven repos :

    <repositories>  
        <repository>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/snapshot</url>
        </repository>
        <repository>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
        </repository>
    </repositories>

Please let me know if this resolves your problem.