I can't exclude MongoAutoConfiguration in Springboot-Kotlin MongoSocketOpenException
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
A MongoSocketOpenException at Spring Boot startup usually means some Mongo-related auto-configuration is still active and is trying to create a client or repository bean. Excluding only MongoAutoConfiguration is often not enough because Spring Boot can also enable data and reactive Mongo auto-configuration depending on the dependencies on your classpath.
Why One Exclusion Often Fails
Spring Boot does not treat Mongo support as one single switch. A project may activate multiple configuration paths:
- core Mongo client configuration
- Mongo data configuration
- Mongo repositories
- reactive Mongo configuration
So this can still be incomplete:
If a second Mongo configuration path is still active, Spring may keep trying to wire beans and open a socket.
Exclude the Synchronous Mongo Stack
If the application should start with no Mongo support at all, exclude both the client and data layers.
That is the usual starting point for a non-reactive application that should boot without touching Mongo.
Add Reactive Exclusions When Reactive Mongo Is Present
If your dependency tree includes reactive Mongo support, exclude those auto-configurations too.
Without these additional exclusions, a reactive bean path may still trigger connection attempts.
Use Profile-Specific Exclusion for Tests
If production needs Mongo but tests do not, do not disable it globally in the main application class. Instead, exclude it only in a test profile.
Then activate that profile for the test.
That keeps production wiring intact while allowing lightweight test startup.
Check for Custom Beans and Repository Activation
If exclusions appear to have no effect, the problem may no longer be Boot auto-configuration. Check for:
- a custom
MongoClientbean in your own code - repository interfaces that still activate Mongo support
- transitive dependencies pulling in reactive or repository starters
- active properties still pointing at a Mongo host
At that point, adding more exclusion lines blindly is less useful than inspecting the actual bean graph and dependency tree.
Dependency Shape Matters in Kotlin Projects Too
Because Spring Boot auto-configuration is classpath-driven, the real fix is often not just an annotation. It may also be removing an unnecessary starter dependency. If a module should not use Mongo, the cleanest answer can be to remove the Mongo starter from that module entirely.
That is often a better long-term fix than accumulating exclusions that future contributors will not immediately understand.
Common Pitfalls
- Excluding only
MongoAutoConfigurationand assuming that disables the whole Mongo stack. - Disabling Mongo globally when only tests needed the exclusion.
- Forgetting that reactive Mongo auto-configuration is separate from the synchronous path.
- Looking only at Boot exclusions while a custom Mongo bean or repository still forces connection creation.
- Keeping unnecessary Mongo starters on the classpath and then fighting their auto-configuration effects.
Summary
- '
MongoSocketOpenExceptionat startup usually means some Mongo configuration path is still active.' - Excluding only
MongoAutoConfigurationis often not enough. - Add data and reactive exclusions when those parts of the stack are present.
- Use test-profile exclusions if only tests should avoid Mongo.
- Inspect dependencies, repositories, and custom beans if exclusions do not solve the problem.
Related reading
- id autoincrement/sequence emulation with CassandraDB/MongoDB etc
- Ids for this class must be manually assigned before calling save on String ID
- If Dynamic columns are discouraged in cassandra 1.2/Cql3 , then how is it better than Mysql in functionality?
- ''IF'' in ''SELECT'' statement - choose output value based on column values
- I get exception when using Thread.sleep(x) or wait()
- I want to get Year, Month, Day, etc from Java Date to compare with Gregorian Calendar date in Java. Is this possible?
- I can’t find the Android keytool
- I get conflicting provisioning settings error when I try to archive to submit an iOS app

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.