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
public class TaskView {
@Id
public String id;
public String title;
public static List<TaskView> all(@FromServices TaskViewRepository tasks) {
return tasks.findAll();
}
}
interface TaskViewRepository extends JpaRepository<TaskView, String> { }

View Java snippet source on GitHub

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: