0

I am working on spring, flowable and mongodb.

here is my pow

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.4.5</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>demo</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>11</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.flowable</groupId>
            <artifactId>flowable-engine</artifactId>
            <version>6.6.0</version>
        </dependency>
        <dependency>
            <groupId>org.flowable</groupId>
            <artifactId>flowable-process-engine-mongodb</artifactId>
            <version>6.4.0.alpha1</version>
        </dependency>


    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

when running, it throws out an error

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

com.mongodb.MongoClientOptions.<init>(MongoClientOptions.java:149)

The following method did not exist:

    'com.mongodb.connection.ConnectionPoolSettings$Builder com.mongodb.connection.ConnectionPoolSettings$Builder.maxWaitQueueSize(int)'

The method's class, com.mongodb.connection.ConnectionPoolSettings$Builder, is available from the following locations:

    jar:file:/Users/abc/.m2/repository/org/mongodb/mongodb-driver-core/4.1.2/mongodb-driver-core-4.1.2.jar!/com/mongodb/connection/ConnectionPoolSettings$Builder.class

The class hierarchy was loaded from the following locations:

    com.mongodb.connection.ConnectionPoolSettings.Builder: file:/Users/abc/.m2/repository/org/mongodb/mongodb-driver-core/4.1.2/mongodb-driver-core-4.1.2.jar

Action:

Correct the classpath of your application so that it contains a single, compatible version of com.mongodb.connection.ConnectionPoolSettings$Builder

firstly, i don't know where maxWaitQueueSize function is being used, because this function exists in mongodb driver 3.6.0-beta1 not in 4.x.x version,

I tried add the pom

    <dependency>
        <groupId>org.mongodb</groupId>
        <artifactId>mongo-java-driver</artifactId>
        <version>3.6.0-beta1</version>
    </dependency>

then running the pom with new errors saying

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

    com.mongodb.MongoClientOptions.<init>(MongoClientOptions.java:149)

The following method did not exist:

    'com.mongodb.connection.ConnectionPoolSettings$Builder com.mongodb.connection.ConnectionPoolSettings$Builder.maxWaitQueueSize(int)'

The method's class, com.mongodb.connection.ConnectionPoolSettings$Builder, is available from the following locations:

    jar:file:/Users/abc/.m2/repository/org/mongodb/mongodb-driver-core/4.1.2/mongodb-driver-core-4.1.2.jar!/com/mongodb/connection/ConnectionPoolSettings$Builder.class
    jar:file:/Users/abc/.m2/repository/org/mongodb/mongo-java-driver/3.6.0-beta1/mongo-java-driver-3.6.0-beta1.jar!/com/mongodb/connection/ConnectionPoolSettings$Builder.class

The class hierarchy was loaded from the following locations:

    com.mongodb.connection.ConnectionPoolSettings.Builder: file:/Users/xisizhe/.m2/repository/org/mongodb/mongodb-driver-core/4.1.2/mongodb-driver-core-4.1.2.jar

I tried to delete the mongodb-driver-core-4.1.2.jar, but when running again the mongodb-driver-core-4.1.2.jar will be downloading automatically again, and the project will keep using the 4.1.2 version instead of mongo-java-driver-3.6.0 configured in the pom.xml

[INFO] --------------------------< com.example:demo >--------------------------
[INFO] Building demo 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] >>> spring-boot-maven-plugin:2.3.3.RELEASE:run (default-cli) > test-compile @ demo >>>
Downloading from central: https://repo.maven.apache.org/maven2/org/mongodb/mongodb-driver/3.8.2/mongodb-driver-3.8.2.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/mongodb/mongodb-driver/3.8.2/mongodb-driver-3.8.2.pom (1.8 kB at 1.0 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/mongodb/bson/4.0.5/bson-4.0.5.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/mongodb/bson/4.0.5/bson-4.0.5.pom (1.3 kB at 2.7 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/mongodb/mongodb-driver-core/4.0.5/mongodb-driver-core-4.0.5.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/mongodb/mongodb-driver-core/4.0.5/mongodb-driver-core-4.0.5.pom (3.1 kB at 7.6 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/mongodb/mongodb-driver/3.8.2/mongodb-driver-3.8.2.jar
Downloading from central: https://repo.maven.apache.org/maven2/org/mongodb/mongodb-driver-core/4.0.5/mongodb-driver-core-4.0.5.jar
Downloading from central: https://repo.maven.apache.org/maven2/org/mongodb/bson/4.0.5/bson-4.0.5.jar
Downloaded from central: https://repo.maven.apache.org/maven2/org/mongodb/mongodb-driver/3.8.2/mongodb-driver-3.8.2.jar (320 kB at 339 kB/s)
Downloaded from central: https://repo.maven.apache.org/maven2/org/mongodb/bson/4.0.5/bson-4.0.5.jar (492 kB at 178 kB/s)
Downloaded from central: https://repo.maven.apache.org/maven2/org/mongodb/mongodb-driver-core/4.0.5/mongodb-driver-core-4.0.5.jar (1.6 MB at 550 kB/s)

The thing puzzled me most is I don't configured any mongodb-driver-core-4.1.2 in the pom.xml, where it is coming from ?

is there a way to solve this?

user824624
  • 7,077
  • 27
  • 106
  • 183
  • Try using a newer version of [MongoDB Java Driver](https://mongodb.github.io/mongo-java-driver/). Also, use the driver installation instructions from the provided link. – prasad_ May 19 '21 at 05:31

2 Answers2

3

I wasn't quite able to reproduce your issue with your pom, I got the following:

Factory method 'mongo' threw exception; nested exception is java.lang.NoClassDefFoundError: com/mongodb/connection/DefaultClusterFactory

Regardless, the issue is most likely that MongoAutoConfiguration, which kicks in when there is an available MongoClient in the classpath is incompatible with the mongodb-driver version that the flowable-process-engine-mongodb lib depends on. If you run mvn dependency:tree you will see the following:

[INFO] \- org.flowable:flowable-process-engine-mongodb:jar:6.4.0.alpha1:compile
[INFO]    +- org.mongodb:mongodb-driver:jar:3.8.2:compile
[INFO]    |  +- org.mongodb:bson:jar:4.1.2:compile
[INFO]    |  \- org.mongodb:mongodb-driver-core:jar:4.1.2:compile

Simply excluding this jar from this dependency allows me to run the app, like so:

<dependency>
    <groupId>org.flowable</groupId>
    <artifactId>flowable-process-engine-mongodb</artifactId>
    <version>6.4.0.alpha1</version>
    <exclusions>
        <exclusion>
            <groupId>org.mongodb</groupId>
            <artifactId>mongodb-driver</artifactId>
        </exclusion>
    </exclusions>
</dependency>

But you probably want to configure a MongoClient in your application, in which case you will need to replace the excluded jar:

<dependency>
    <groupId>org.mongodb</groupId>
    <artifactId>mongodb-driver-sync</artifactId>
</dependency>

Which is a synchronous driver for mongoDB but you can use the async driver as well. You don't have to provide a version as it's a managed dependency.

Alternatively, you could exclude the MongoAutoConfiguration in your main application class:

@SpringBootApplication(exclude = MongoAutoConfiguration.class)
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

}

Which would allow you to keep the original dependency but you won't have any of the Beans available that would otherwise be configured in the MongoAutoConfiguration configuration class.

Krisz
  • 1,884
  • 12
  • 17
0

I was also facing the same exception. I just removed the mongo dependency from pom.xml and just used what spring boot provided and it did work.