spring – Fongo – 找不到OperationExecutor

我想在我的
Spring启动应用程序中使用fongo 2.0.x,但是我得到了错误

Error:(23, 44) java: cannot access com.mongodb.operation.OperationExecutor
class file for com.mongodb.operation.OperationExecutor not found

这是我的AbstractMongoConfiguration

@Configuration
@ComponentScan("com.foo")
public class MongoDbConfig extends AbstractMongoConfiguration {

    @Override
    protected String getDatabaseName() {
        return "demo";
    }

    @Override
    public Mongo mongo() throws Exception {
        return new Fongo(getDatabaseName()).getMongo(); //this line throws the error
    }
}

最佳答案 从
Fongo documentation

It has a “provided” dependency on the mongo-java-driver and was tested with 2.13.0 and 3.0.1.

所以Fongo想要在类路径上使用mongo-java-driver,我猜你没有它(或者至少不在测试范围内).

因此,请确保您的构建脚本中包含以下内容:

对于Maven:

<dependency>
  <groupId>org.mongodb</groupId>
  <artifactId>mongo-java-driver</artifactId>
  <version>3.4.1</version>
  <scope>test</scope>
</dependency>

对于Gradle:

testCompile 'org.mongodb:mongo-java-driver:3.4.1'
点赞