Spring Boot FAQ: Top Questions
21. How does Spring Boot support H2 Database for development?
Spring Boot provides seamless integration with the H2 in-memory database, ideal for development and testing purposes.
πΊοΈ Setup:
- Add the
spring-boot-starter-data-jpa
andcom.h2database:h2
dependencies. - Configure the H2 console and datasource settings in
application.properties
.
π₯ Example:
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driverClassName=org.h2.Driver
spring.h2.console.enabled=true
π Expected Output:
Launch H2 console at /h2-console and interact with in-memory database.
π οΈ Use Cases:
- Lightweight testing without external DB setup.
- Rapid prototyping and schema validation.