Spring Boot does not have a default database in the sense of always creating one. It only auto-configures an embedded database, usually H2, when no DataSource is configured and an embedded database driver (H2, HSQLDB or Derby) is on the classpath. If you add only spring-boot-starter-data-jpa and no driver, the application fails at startup with a "Failed to determine a suitable driver class" error.
When an embedded database is used, it runs in memory, so its data is lost when the application stops. This is useful for tests and prototypes, but you should configure a real database such as PostgreSQL or MySQL for anything you deploy.
Spring Boot's DataSourceAutoConfiguration looks for a DataSource bean and for spring.datasource.* properties. If neither exists, it checks whether one of the supported embedded databases is on the classpath. The supported ones are H2, HSQLDB and Apache Derby. If it finds one, it creates an in-memory DataSource for you.
This means the "default" depends entirely on your dependencies:
| Situation | Result |
|---|---|
| No JDBC driver on the classpath | Startup fails when a DataSource is required |
| Only H2 on the classpath, no properties | In-memory H2 database is created |
H2 plus spring.datasource.url for PostgreSQL | Your configured PostgreSQL database is used |
| PostgreSQL driver but no URL | Startup fails, because Boot does not guess a server address |
Add the starter and the H2 driver as a runtime dependency. With Maven:
With no other configuration, a JPA entity and a repository work immediately:
For an embedded database Spring Boot also sets spring.jpa.hibernate.ddl-auto to create-drop, so Hibernate creates the tables at startup and drops them at shutdown. For a non-embedded database the default is none, which is why you must manage the schema yourself there.
By default Boot generates a unique in-memory database name on each start. To use a stable name, or to keep data in a file, set the URL yourself in application.properties:
With spring.h2.console.enabled=true and the spring-boot-devtools or web starter present, you can open /h2-console in the browser and run SQL against the running database. Enable the console only in development, because it exposes your data.
To keep data between restarts, use a file URL such as jdbc:h2:file:./data/demo. H2 is then still embedded, but it persists to disk.
Replace the H2 dependency with the driver you need and set the connection properties. For PostgreSQL:
Boot detects the driver class from the URL, so spring.datasource.driver-class-name is rarely needed. Use validate or none with a migration tool such as Flyway or Liquibase, both of which Boot configures automatically when they are on the classpath.
H2 can behave differently from PostgreSQL or MySQL in SQL dialect, locking and types. For realistic tests, use Testcontainers with @ServiceConnection (Spring Boot 3.1 and later), which starts a real database in a container and wires the connection automatically:
Note that @DataJpaTest replaces your configured DataSource with an embedded one by default. Add @AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE) if you want it to use the real or containerised database.
Only in effect. Boot has no built-in database, but if H2 is the embedded driver on the classpath and you configure nothing else, it creates an in-memory H2 database.
No spring.datasource.url is set and no embedded database is on the classpath. Add a driver and a URL, or add H2 for local development.
No. In-memory data lives in the JVM and disappears at shutdown. Use a file URL or a real database to persist it.
No. Use a server database such as PostgreSQL or MySQL, and use H2 or a Testcontainers database only for development and tests.
Spring Boot has no default database of its own. It auto-configures an embedded in-memory database such as H2 only when the driver is on the classpath and no DataSource is configured. Set spring.datasource.* for real databases, manage the schema with Flyway or Liquibase, and prefer Testcontainers when your tests need production-like behaviour.