我有以下Spring Data MongoDb Repository Java配置:
@EnableMongoRepositories(basePackages= {"com.example.repositories.mongodb"})
public class MongoConfig extends AbstractMongoConfiguration {
private @Value("${mongo.host}") String mongoHost;
private @Value("${mongo.port}") int mongoPort;
private @Value("${mongo.database}") String mongoDatabase;
@Override
protected String getDatabaseName() {
return mongoDatabase;
}
@Override
public Mongo mongo() throws Exception {
MongoClientOptions options = MongoClientOptions.builder()
.connectionsPerHost(100)
.connectTimeout(120000)
.socketTimeout(120000)
.maxWaitTime(1200000)
.threadsAllowedToBlockForConnectionMultiplier(1500)
.writeConcern(WriteConcern.ACKNOWLEDGED)
.build();
MongoClient client = new MongoClient(new ServerAddress(mongoHost, mongoPort), options);
return client;
}
public @Bean PersistenceExceptionTranslationPostProcessor exceptionTranslation() {
return new PersistenceExceptionTranslationPostProcessor();
}
}
我试图弄清楚writeConcern是否真的打开了,因为一些jUnits在重复运行时不起作用。如果我在上面创建客户端后放置一个断点并检查客户端对象,我可以看到它的属性WriteConcern等于:
{w = null,wTimeout = null ms,fsync = null,journal = null}
这告诉我它没有设置为确认。
我是否正确设置并且有没有办法确定是否设置了正确的问题?我试过的记录器选项都没有输出。
我的依赖关系是:
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>3.5.0</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>${spring.data.mongodb}</version>
</dependency>