Use Spring Data read models
Add an integration
Section titled “Add an integration”Choose the store used by the application:
// JPAdependencies { implementation("io.cratis:arc-spring-data-jpa:<version>")}// MongoDBdependencies { 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.
Inject a repository into a query
Section titled “Inject a repository into a query”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@ReadModeldata 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:
- Map JPA concepts — attribute converters and embedded ids.
- Map MongoDB concepts — concrete scalar pairs and identifiers.
- Repositories in queries and commands — paging, current state, tenant-bound access and transactions.
- Observable storage snapshots — change streams and JPA notifications.