【发布时间】:2021-04-12 15:58:09
【问题描述】:
我正在尝试在具有 Axon 的 extensions.mongo 依赖项的 Spring Boot 项目上运行 mvn clean install。 mongo 数据库在 docker 容器中启动并运行
在我的 pom 中:
<dependency>
<groupId>org.axonframework.extensions.mongo</groupId>
<artifactId>axon-mongo</artifactId>
<version>4.3</version>
</dependency>
然后我有一个 @Configuration 类,其中包括这些成员:
@Value("${spring.data.mongodb.host:127.0.0.1}")
private String mongoHost;
@Value("${spring.data.mongodb.port:27017}")
private int mongoPort;
@Value("${spring.data.mongodb.database:user}")
private String mongoDatabase;
@Bean
public MongoClient mongoClient() {
var mongoFactory = new MongoFactory();
mongoFactory.setMongoAddresses(Collections.singletonList(new ServerAddress(mongoHost, mongoPort)));
return mongoFactory.createMongo();
}
然后在运行mvn clean install 时,我得到了这个堆栈跟踪:
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoClient' defined in com.springbank.user.core.configuration.AxonConfig: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.mongodb.MongoClient]: Factory method 'mongoClient' threw exception; nested exception is java.lang.NoSuchMethodError: 'com.mongodb.connection.ConnectionPoolSettings$Builder com.mongodb.connection.ConnectionPoolSettings$Builder.maxWaitQueueSize(int)'
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.mongodb.MongoClient]: Factory method 'mongoClient' threw exception; nested exception is java.lang.NoSuchMethodError: 'com.mongodb.connection.ConnectionPoolSettings$Builder com.mongodb.connection.ConnectionPoolSettings$Builder.maxWaitQueueSize(int)'
Caused by: java.lang.NoSuchMethodError: 'com.mongodb.connection.ConnectionPoolSettings$Builder com.mongodb.connection.ConnectionPoolSettings$Builder.maxWaitQueueSize(int)'
【问题讨论】:
-
您使用的版本不兼容。此外,
mongoclient已经可以通过自动配置获得,因此不需要。 -
感谢您的输入;我在另一个问题中看到可能是这种情况-但是在这种情况下兼容的版本是什么?我的意思是有一个我可以使用的版本来应用这个配置吗?我尝试了其他 - 低至 4.1 但似乎没有任何工作
-
4.1 的什么?这看起来就像您正在使用与您正在使用的 Spring Mongo 版本不兼容的 Mongo 驱动程序。当您使用 Spring Boot 时,这可能意味着您对版本的使用过多。
-
我指的是 org.axonframework.extensions.mongo 依赖项;我尝试了 4.3,也尝试了其他版本(包括 4.1);我认为这就是您所说的不兼容版本的意思- mongo 扩展。所以基本上我尝试更改mongo驱动程序的版本,然后重试
mvn clean install -
正如提到的
MongoFactory(无论提供该类的什么),期待您当前使用的 MonogDB 版本的更新/旧版本。恕我直言,您不需要该方法,Spring Boot 会自动为您配置MongoClient。
标签: mongodb spring-boot axon-framework