How to Solve SpringBoot MongoDB MongoAutoConfiguration Startup Error


SpringBoot project needs to manually control whether to load MongoDB auto-configuration (i.e.: MongoAutoConfiguration), then startup error

- Bean method 'mongoTemplate' in 'MongoDatabaseFactoryDependentConfiguration' not loaded because @ConditionalOnBean (types:; SearchStrategy: all) did not find any beans of type


@Import(value = {MongoDataAutoConfiguration.class, MongoAutoConfiguration.class})

Solution: Replace @Import content order, load MongoAutoConfiguration first

@Import(value = {MongoAutoConfiguration.class, MongoDataAutoConfiguration.class})

Read More: