Jeg løste dette problem med den næste konfiguration:
@Configuration
@EnableMongoRepositories(basePackages = "YOUR.PACKAGE")
@EnableMongoAuditing
public class MongoConfig extends AbstractMongoConfiguration {
@Value("${spring.data.mongodb.host}")
private String host;
@Value("${spring.data.mongodb.port}")
private Integer port;
@Value("${spring.data.mongodb.database}")
private String database;
@Override
public MongoClient mongoClient() {
return new MongoClient(host, port);
}
@Override
protected String getDatabaseName() {
return database;
}
@Bean
public MongoTemplate mongoTemplate() throws Exception {
return new MongoTemplate(mongoDbFactory(), mappingMongoConverter());
}
@Bean
public MongoDbFactory mongoDbFactory() {
return new SimpleMongoDbFactory(mongoClient(), database);
}
}
bare tilføje bønnen for MongoTemplate
med konstruktøren af MongoTemplate(MongoDbFactory mongoDbFactory, @Nullable MongoConverter mongoConverter)