Search⌘ K
AI Features

Defining Our E-commerce Application’s Domain

Explore defining core domain models for an e-commerce app using Spring Boot's reactive programming and MongoDB. Understand how to create inventory, cart items, and cart objects aligned with best data modeling practices.

In this lesson, now that we’re embracing a real database, we can actually start modeling our e-commerce site. Let’s start with a new project created using Spring Initializr.

Adding database dependencies

First, we’ll add some new dependencies to our pom.xml build file:

XML
<dependencies>
<!-- tag::mongodb[] -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb-reactive</artifactId>
</dependency>
<dependency>
<groupId>de.flapdoodle.embed</groupId>
<artifactId>de.flapdoodle.embed.mongo</artifactId>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-sync</artifactId>
</dependency>
<!-- end::mongodb[] -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
The MongoDB dependencies added to our pom.xml build file

Line 5 has the first dependency, spring-boot-starter-data-mongodb-reactive, which is one of Spring Boot’s startersSpringBootStarter, as shown in pom.xml.

There are many reactive datastore modules in Spring Boot.

Reactive datastore modules

Module

Description

spring-boot-starter

Core Spring Boot module that glues things together

spring-data-mongodb

Spring Data MongoDB itself, but with the blocking MongoDB drivers excluded

mongodb-driver-reactivestreams

MongoDB’s official Reactive Streams driver

That starter introduces Spring Data MongoDB. Specifically, it introduces the reactive version of that library. A classic spring-boot-starter-data-mongodb start also uses MongoDB’s classic blocking API. Spring Data MongoDB has complete support for Reactive Streams and ...