Skip to content

Use Spring Data read models

Choose the store used by the application:

// JPA
dependencies {
implementation("io.cratis:arc-spring-data-jpa:<version>")
}
// MongoDB
dependencies {
implementation("io.cratis:arc-spring-data-mongodb:<version>")
}

Both modules include the Arc Spring Boot starter and the corresponding Spring Data starter. Spring Boot continues to own the datasource, entity manager, Mongo client, repository discovery, and their standard configuration.

Spring Data repositories are ordinary Spring services. Mark a model-bound query dependency with @FromServices; Arc’s generated performer resolves the repository from the current application context.

@Entity
@ReadModel
data class TaskView(@Id val id: String = "", val title: String = "") {
companion object {
@JvmStatic
fun all(@FromServices tasks: TaskViewRepository): List<TaskView> = tasks.findAll()
}
}
interface TaskViewRepository : JpaRepository<TaskView, String>

The same pattern works with MongoRepository, repository fragments, and application query services. An application bean replaces an auto-configured adapter bean of the same integration contract.

Storing a domain concept, routing by tenant and streaming changes each need their own setup: