我在spring、flowable和MongoDB上工作。
这是我的战俘
<?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>
运行时,它抛出一个错误
试图调用不存在的方法。尝试是从以下位置进行的:
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
Correct the classpath of your application so that it contains a single, compatible version of com.mongodb.connection.ConnectionPoolSettings$Builder
首先,我不知道maxWaitQueueSize函数在哪里使用,因为这个函数存在于mongodb driver 3.6.0-beta1中,而不存在于4.x.x版本中,
我试着加了pom
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>3.6.0-beta1</version>
</dependency>
然后运行带有新错误的pom
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
我试图删除mongodb-driver-core-4.1.2.jar,但再次运行mongodb-driver-core-4.1.2.jar时,将再次自动下载mongodb-driver-core-4.1.2.jar,项目将继续使用4.1.2版本,而不是pom.xml中配置的mongo-java-driver-3.6.0
[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)
最让我困惑的是,我没有在pom.xml中配置任何mongodb-driver-core-4.1.2,它来自哪里?
有办法解决这个吗?
我不能用你的pom复制你的问题,我得到了以下内容:
Factory method 'mongo' threw exception; nested exception is java.lang.NoClassDefFoundError: com/mongodb/connection/DefaultClusterFactory
无论如何,问题很可能是MongoAutoConfiguration
与flowable-process-engine-MongoDB
库所依赖的MongoDB-Driver
版本不兼容,当类路径中有可用的MongoAutoConfiguration
时,MongoAutoConfiguration
就会出现这种情况。如果运行MVN Dependency:Tree
,您将看到以下内容:
[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
简单地将这个jar从这个依赖项中排除,就可以运行应用程序,如下所示:
xml prettyprint-override"><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>
但是您可能希望在应用程序中配置mongoclient
,在这种情况下,您将需要替换排除的JAR:
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-sync</artifactId>
</dependency>
它是mongoDB的同步驱动程序,但是您也可以使用Async
驱动程序。您不必提供版本,因为它是托管依赖项。
@SpringBootApplication(exclude = MongoAutoConfiguration.class)
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
我正在研究示例。下列的https://www.youtube.com/watch?v=lBKZOTe9QM4 如果我使用了和版本到,那么它工作正常。但是我使用3.4版本,然后我在启动时得到以下错误。有什么快速的帮助吗? 波姆。xml 去民主化。JAVA
我正在尝试通过hibernate和Spring-Boot连接MongoDB数据库。当我试图连接到MongoDB时,我得到了以下错误。请帮我通过Hibernate连接。在我的build.gradle中,我只有“hibernate-ogm-mongoDB”依赖项。
我在运行我的Spring boot应用程序时遇到以下错误,我是Spring boot和弹性搜索的新手,请帮助解决这个问题。并在下面附上了我的pom依赖项。提前感谢, ****************************应用程序启动失败***************************************************
我正在使用spring cloud将一个模块化应用程序迁移到一个microsevrices应用程序中,当我将一个模块迁移到microservice并运行它时,出现了一个问题: 更正应用程序的类路径,使其包含org.springframework.plugin.core.pluginregistry的一个兼容版本 这是一个错误: 这是我的pom.xml: 这是我的swaggreconfig.java
试图调用不存在的方法。尝试是从以下位置进行的: 以下方法不存在: 该方法的类javax.persistence.table可从以下位置获得: