MongoDB
 sql >> Database >  >> NoSQL >> MongoDB

Errore di controllo mongodb dell'avvio a molla

Ho risolto questo problema con la configurazione successiva:

@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);
    }
}

aggiungi semplicemente il bean per MongoTemplate con il costruttore di MongoTemplate(MongoDbFactory mongoDbFactory, @Nullable MongoConverter mongoConverter)