Auto-configuration and ownership boundaries
Latest stable Based on Bluetape4k release 2.0.0
Contract scope: 2.0.0 current contract on
develop. The stable rollback reference remains 2.0.0.
What the auto-configuration does
Section titled “What the auto-configuration does”The module’s AutoConfiguration.imports registers only
ReactiveMongoAutoConfiguration. It runs after Spring Boot’s
DataMongoReactiveAutoConfiguration, requires ReactiveMongoOperations on the
classpath, and backs off when an operations bean already exists.
@AutoConfiguration( afterName = [ "org.springframework.boot.data.mongodb.autoconfigure.DataMongoReactiveAutoConfiguration", ],)@ConditionalOnClass(ReactiveMongoOperations::class)@ConditionalOnMissingBean(ReactiveMongoOperations::class)class ReactiveMongoAutoConfiguration : EnvironmentAware { override fun setEnvironment(environment: Environment) { if (environment.containsProperty("spring.data.mongodb.uri") && !environment.containsProperty("spring.mongodb.uri") ) { throw IllegalStateException( "Unsupported legacy MongoDB property 'spring.data.mongodb.uri'; " + "use 'spring.mongodb.uri' on Spring Boot 4.1+", ) } }
@Bean fun reactiveMongoTemplate( databaseFactory: ReactiveMongoDatabaseFactory, mongoConverter: MongoConverter, ): ReactiveMongoTemplate = ReactiveMongoTemplate(databaseFactory, mongoConverter)}It does not create ReactiveMongoDatabaseFactory or MongoConverter. The
fallback can be completed only when both beans are already available.
Property migration and precedence
Section titled “Property migration and precedence”Spring Boot 4.1 binds MongoDB connection settings under spring.mongodb.*.
Use the current URI key:
spring: mongodb: uri: mongodb://127.0.0.1:27018/synthetic| Properties present | Result when the library fallback participates |
|---|---|
spring.mongodb.uri only | Use the current Spring Boot 4.1 namespace |
spring.data.mongodb.uri only | Fail at startup instead of silently using localhost |
| Both keys | spring.mongodb.uri takes precedence |
The legacy-only failure is:
IllegalStateException: Unsupported legacy MongoDB property 'spring.data.mongodb.uri'; use 'spring.mongodb.uri' on Spring Boot 4.1+Use synthetic URIs in tests and keep credentials out of logs and diagnostic artifacts.
Back-off and ownership
Section titled “Back-off and ownership”Spring Boot’s reactive MongoDB auto-configuration normally supplies
ReactiveMongoOperations. The class-level @ConditionalOnMissingBean then
backs off the entire bluetape4k configuration, including the legacy-property
guard. The same rule applies when the application provides its own operations
bean. Adding this artifact therefore does not create a second client or pool.
Use the condition evaluation report to inspect the actual bean graph.
Responsibility map
Section titled “Responsibility map”| Layer | Owned responsibilities |
|---|---|
| bluetape4k module | Coroutine extensions, query DSL, template fallback |
| Spring Boot and Spring Data | Property binding, factory, mapping converter, template, lifecycle integration |
| Application | Custom conversions, auditing, index policy, transactions, domain repositories |
| MongoDB driver | Connection pool, server selection, protocol, sessions, concerns, timeouts |
The presence of MongoDB Kotlin driver dependencies in the build does not move driver configuration into bluetape4k auto-configuration.
Custom conversion and auditing
Section titled “Custom conversion and auditing”The current module does not create a MongoCustomConversions bean or enable
MongoDB auditing. Applications that need either feature should use a separate
configuration.
@Configuration(proxyBeanMethods = false)@EnableMongoAuditingclass MongoDomainConfiguration { @Bean fun mongoCustomConversions(): MongoCustomConversions = MongoCustomConversions.create { adapter -> adapter.registerConverter(MoneyWriteConverter()) }}A converter changes the stored wire format. Verify that old and new application versions can read the same documents before a rolling deployment.
Source and tests
Section titled “Source and tests”ReactiveMongoAutoConfiguration.ktAutoConfiguration.importsReactiveMongoAutoConfigurationTest.ktondevelop- Module build
Next chapter
Section titled “Next chapter”Use the configured template in Coroutine reads and cardinality.