How to disable spring-data-mongodb autoconfiguration in spring-boot

As pointed out by Andy Wilkinson in comments, when using EnableAutoConfiguration with exclude list make sure there are no other classes annotated with EnableAutoConfiguration or SpringBootApplication.


This is how I do it:

@SpringBootApplication(exclude = {
  MongoAutoConfiguration.class, 
  MongoDataAutoConfiguration.class
})

or as suggested by Dan Oak:

spring.autoconfigure.exclude= \
  org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration,\
  org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration