我使用所有持续版本(修复其他问题)
mongobee 0.13
fongo 2.2.0-RC3-SNAPSHOT
mongodb驱动程序3.8.2
当我运行我的应用程序时,出现此错误:
org.springframework.beans.factory.BeanCreationException:在类路径资源 [com/myproject/company/configuration/MongoConfiguration.class] 中定义名称为“mongobeeStandalone”的 bean 创建错误:调用 init 方法失败;嵌套异常是 java.lang.AbstractMethodError: com.mongodb.client.internal.FongoOperationExecutor.execute(Lcom/mongodb/operation/ReadOperation;Lcom/mongodb/ReadPreference;Lcom/mongodb/ReadConcern;)Ljava/lang/Object; ...引起:java.lang.AbstractMethodError:com.mongodb.client.internal.FongoOperationExecutor.execute(Lcom/mongodb/operation/ReadOperation;Lcom/mongodb/ReadPreference;Lcom/mongodb/ReadConcern;)Ljava/lang/Object ;
我的课:
@Bean
public Mongobee mongobeeStandalone(final MongoTemplate mongoTemplate, final MongoClient mongoClient) {
final Mongobee runner = new Mongobee(mongoClient);
runner.setChangeLogsScanPackage(Changelog1.class.getPackage().getName()); // package to scan for changesets
runner.setDbName(mongoTemplate.getDb().getName());
return runner;
}
@Bean
public MongoClient mongoClient(final MongoDbFactory mongoDbFactory) {
final Mongo mongo = mongoDbFactory.getLegacyDb().getMongo();
if (!MongoClient.class.isInstance(mongo)) {
throw new UnsupportedOperationException("Must be a MongoClient");
}
return MongoClient.class.cast(mongo);
}
编辑
我的测试配置:
@Configuration
public class FoncgoConfiguration extends AbstractMongoConfiguration {
@Bean
public Fongo fongo() {
return new Fongo("mongo-test");
}
@Override
@Bean
public MongoTemplate mongoTemplate() throws Exception {
final SimpleMongoDbFactory simpleMongoDbFactory = new SimpleMongoDbFactory(mongoClient(), getDatabaseName());
final MongoTemplate mongoTemplate = new MongoTemplate(simpleMongoDbFactory, mappingMongoConverter());
return mongoTemplate;
}
@Override
@Bean
public MongoClient mongoClient() {
return MockMongoClient.create(fongo());
}
}