liveBook · Manning

Embedded database

As explained in Spring in Action, Sixth Edition

An embedded database is a database engine that runs within the application process or development environment rather than as a separately managed service.

An embedded database runs within the application process or development environment instead of requiring a separately managed database service. It gives development and testing projects a ready-to-use database without installing or starting a separate server. section 4.2.1 section 3.1.2

Embedded databases are useful when you need:

  • A local MongoDB substitute supplied through the Flapdoodle embedded MongoDB dependency. section 4.2.1
  • An in-memory H2 database for Spring JDBC development, with an optional fixed database name for console access. section 3.1.2
  • Clean test or development state, because embedded MongoDB data is wiped when the application restarts. section 4.2.1

Switching from local MongoDB to embedded MongoDB

Spring Data MongoDB normally expects a MongoDB server on localhost:27017. Adding the Flapdoodle dependency removes that separate-server requirement for development and testing. For production, configure the external MongoDB host, port, credentials, and database name instead. section 4.2.1

<dependency>
  <groupId>de.flapdoodle.embed</groupId>
  <artifactId>de.flapdoodle.embed.mongo</artifactId>
  <!-- <scope>test</scope> -->
</dependency>

Use the Flapdoodle dependency to add an embedded MongoDB implementation to a Spring Boot build. section 4.2.1

spring:
  data:
    mongodb:
      host: mongodb.tacocloud.com
      port: 27017
      username: tacocloud
      password: s3cr3tp455w0rd
      database: tacoclouddb

Use these Spring Data MongoDB properties when production data lives in an externally managed MongoDB server. section 4.2.1

How Spring in Action, Sixth Edition covers it

How deep it goes
Explains dependency and configuration choices, then defers production deployment to external database properties.
Examples
Uses Flapdoodle embedded MongoDB and H2 in-memory databases, including fixed H2 naming for console connections.
What it assumes
Assumes a Spring Boot project and introduces database dependencies and properties through MongoDB and JDBC examples.
What you can do after
Configure an embedded MongoDB or H2 database for development and testing, then point Spring Data MongoDB at production infrastructure.
How it connects
Connects embedded databases with Spring Boot, Spring Data MongoDB, H2, and JdbcTemplate.

Also explained in

Compare how 2 books explain embedded database →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring in Action, Sixth Edition. The section links point to the parts of the book it draws on.