Using H2 for Development in CAP Java
For local development and testing, CAP Java supports the H2 database, which can be configured to run in-memory.
Learn more about features and limitations of using CAP with H2
WARNING
Not supported for CAP Node.js.
Setup & Configuration
Using the Maven Archetype
When a new CAP Java project is created with the Maven Archetype or with cds init
, H2 is automatically configured as in-memory database used for development and testing in the default
profile.
Manual Configuration
To use H2, just add a Maven dependency to the H2 JDBC driver:
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
Next, configure the build to create an initial schema.sql file for H2 using cds deploy --to h2 --dry
.
In Spring, H2 is automatically initialized as in-memory database when the driver is present on the classpath.
Learn more about the configuration of H2
Features
CAP supports most of the major features on H2: