How do you configure Embedded MongDB for integration testing in a Spring Boot application?

Since Spring Boot version 1.3 there is an EmbeddedMongoAutoConfiguration class which comes out of the box. This means that you don’t have to create a configuration file at all and if you want to change things you still can.

Auto-configuration for Embedded MongoDB has been added. A dependency on de.flapdoodle.embed:de.flapdoodle.embed.mongo is all that’s necessary to get started. Configuration, such as the version of Mongo to use, can be controlled via application.properties. Please see the documentation for further information. (Spring Boot Release Notes)

The most basic and important configuration that has to be added to the application.properties files is
spring.data.mongodb.port=0 (0 means that it will be selected randomly from the free ones)

for more details check: Spring Boot Docs MongoDb

Leave a Comment