0

I am using emdedded mongodb (flapdoodle) in my tests. I am moving to Spring Boot 3. I got help from this link: How to use embedded MongoDB with SpringBoot v3.0.0? (@egimaben answer).

Now if I want to be able to create the mongo client (mongotemplate), I need to know in advance the port. So I am using a fixed port to start MongoDB server:

spring.data.mongodb.port=27777

Then I create the client (Mongotemplate) to connect to this port. Everything works fine.

But if I have multiple tests, each test is trying to start MongoDB server and fails since the port is busy. How can I start/stop embedded MongoDB for each test? or If I use random port instead of fixed port, how can I know in advance the random port in order to create the Mongo client (mongoTemplate)?

Thank you for your help.

Mykeul
  • 498
  • 1
  • 6
  • 20

0 Answers0