Skip to content
Bluetape4k docs2.0

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.

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.

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 presentResult when the library fallback participates
spring.mongodb.uri onlyUse the current Spring Boot 4.1 namespace
spring.data.mongodb.uri onlyFail at startup instead of silently using localhost
Both keysspring.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.

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.

LayerOwned responsibilities
bluetape4k moduleCoroutine extensions, query DSL, template fallback
Spring Boot and Spring DataProperty binding, factory, mapping converter, template, lifecycle integration
ApplicationCustom conversions, auditing, index policy, transactions, domain repositories
MongoDB driverConnection 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.

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)
@EnableMongoAuditing
class 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.

Use the configured template in Coroutine reads and cardinality.