[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move from [deprecated] mongo-java-driver #80

Closed
elgleidson opened this issue Jan 17, 2021 · 2 comments · Fixed by #100
Closed

Move from [deprecated] mongo-java-driver #80

elgleidson opened this issue Jan 17, 2021 · 2 comments · Fixed by #100

Comments

@elgleidson
Copy link
elgleidson commented Jan 17, 2021

I was trying to run liquibase extension for mongodb in my project but it doesn't work due to use of [deprecated] mongo-java-driver, which is not being published anymore - https://mongodb.github.io/mongo-java-driver/4.0/upgrading/#upgrading-from-the-3-12-java-driver

Since I'm using Spring Data MongoDB (spring-boot-starter-data-mongodb-reactive which in turn brings mongodb-driver-reactivestreams or spring-boot-starter-data-mongodb which in turn brings mongodb-driver-sync and both bring mongodb-driver-core), this causes the following error:

***************************
APPLICATION FAILED TO START
***************************

Description:

An attempt was made to call a method that does not exist. The attempt was made from the following location:

    com.mongodb.internal.connection.DefaultClusterFactory.createCluster(DefaultClusterFactory.java:85)

The following method did not exist:

    'void com.mongodb.internal.connection.DefaultClusterableServerFactory.<init>(com.mongodb.connection.ClusterId, com.mongodb.connection.ClusterSettings, com.mongodb.connection.ServerSettings, com.mongodb.connection.ConnectionPoolSettings, com.mongodb.connection.StreamFactory, com.mongodb.connection.StreamFactory, com.mongodb.MongoCredential, com.mongodb.event.CommandListener, java.lang.String, com.mongodb.MongoDriverInformation, java.util.List)'

The method's class, com.mongodb.internal.connection.DefaultClusterableServerFactory, is available from the following locations:

    jar:file:/Users/elgleidson/.m2/repository/org/mongodb/mongo-java-driver/3.12.7/mongo-java-driver-3.12.7.jar!/com/mongodb/internal/connection/DefaultClusterableServerFactory.class
    jar:file:/Users/elgleidson/.m2/repository/org/mongodb/mongodb-driver-core/4.0.5/mongodb-driver-core-4.0.5.jar!/com/mongodb/internal/connection/DefaultClusterableServerFactory.class

The class hierarchy was loaded from the following locations:

    com.mongodb.internal.connection.DefaultClusterableServerFactory: file:/Users/elgleidson/.m2/repository/org/mongodb/mongo-java-driver/3.12.7/mongo-java-driver-3.12.7.jar


Action:

Correct the classpath of your application so that it contains a single, compatible version of com.mongodb.internal.connection.DefaultClusterableServerFactory


Process finished with exit code 1

┆Issue is synchronized with this Jira Bug by Unito

@jsonking
Copy link
jsonking commented Jan 22, 2021

Hi @elgleidson,

It looks like you have two versions of the driver on your classpath:

  • 3.12.7 via liquibase
  • 4.0.5 via your own project

You can prevent the version coming through from liquibase by adding exclusions to your pom.xml if using maven. e.g:

<dependency>
    <groupId>org.liquibase.ext</groupId>
    <artifactId>liquibase-mongodb</artifactId>
    <version>4.2.1</version>
    <exclusions>
        <exclusion>
            <groupId>org.mongodb</groupId>
            <artifactId>mongo-java-driver</artifactId>
        </exclusion>
        <exclusion>
            <groupId>org.mongodb</groupId>
            <artifactId>mongodb-driver</artifactId>
        </exclusion>
        <exclusion>
            <groupId>org.mongodb</groupId>
            <artifactId>bson</artifactId>
        </exclusion>
    </exclusions>
</dependency>

That should fix the specific error you are seeing.

However liquibase still won't work and you are likely to get an error such as:

INFO: Successfully released change log lock
Exception in thread "main" java.lang.NoSuchMethodError: com.mongodb.client.MongoCollection.insertOne(Ljava/lang/Object;)V
	at liquibase.ext.mongodb.statement.InsertOneStatement.execute(InsertOneStatement.java:75)
	at liquibase.ext.mongodb.statement.InsertOneStatement.execute(InsertOneStatement.java:33)
	at liquibase.nosql.executor.NoSqlExecutor.execute(NoSqlExecutor.java:180)
	at liquibase.nosql.executor.NoSqlExecutor.execute(NoSqlExecutor.java:173)
	at liquibase.ext.mongodb.changelog.MongoHistoryService.markChangeSetRun(MongoHistoryService.java:184)

This is caused by the signature of MongoCollection.insertOne changing from returning void in driver version 3.12.x to returning an InsertOneResult in version 4.0.x and later.

Thus liquibase needs to be recompiled against a newer driver version such as 4.1.1 OR the code updated to work with both 3.12.x and 4.x versions if possible.

I noticed that there is another issue already open directly asking about support for the newer 4.x driver versions: #71

Can I suggest closing this issue and add a comment to #71 so that you are notified of updates?

Jason

@alexandru-slobodcicov
Copy link

Hi @elgleidson changed the driver to 4x , additionally made compatible with 3x by @jsonking suggestion. See associated PR. Change will be part of 4.3.1 and upper

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants