今天使用springBoot-data-mongodb时提示如下信息:
Please use 'MongoMappingContext#setAutoIndexCreation(boolean)' or override 'MongoConfigurationSupport#autoIndexCreation()' to be explicit.
However, we recommend setting up indices manually in an application ready block. You may use index derivation there as well.
> -----------------------------------------------------------------------------------------
> @EventListener(ApplicationReadyEvent.class)
> public void initIndicesAfterStartup() {
>
> IndexOperations indexOps = mongoTemplate.indexOps(DomainType.class);
>
> IndexResolver resolver = new MongoPersistentEntityIndexResolver(mongoMappingContext);
> resolver.resolveIndexFor(DomainType.class).forEach(indexOps::ensureIndex);
> }
> -----------------------------------------------------------------------------------------
原因:因为在SpringBoot-data-MongoDB的2.2.1版本之后自动创建索引的方式已经不被推荐。
解决办法:
在application.properties配置文件内添加如下内容即可
spring.data.mongodb.auto-index-creation=false
解决!!!
如果觉得对你有用,那不妨关注下面公众号交流!!