Configuring H2 Database in Spring Boot
In this article, we will learn how to configure an H2 database in a Spring Boot application. H2 is an open-source, in-memory, Java SQL database. It is very lightweight and its small footprint makes it suitable for use in embedded applications. We will also learn how to access the H2 console to view and manipulate the data stored in the database.
Introduction
H2 is an open-source, in-memory, Java SQL database. It is very lightweight and its small footprint makes it suitable for use in embedded applications. It supports both embedded and server modes. In embedded mode, the database runs in the same JVM as the application. In server mode, the database runs in a separate process, which can be accessed from multiple applications.
H2 is written in Java and is compatible with all major operating systems. It supports a wide range of SQL features, including stored procedures, triggers, and user-defined functions. It also supports the latest JDBC 4.2 API.
Configuring H2 Database in Spring Boot
Configuring an H2 database in a Spring Boot application is straightforward. We need to add the H2 dependency in the pom.xml
file.
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
We also need to configure the database connection in the application.properties
file.
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=
The spring.datasource.url
property specifies the URL of the database. The spring.datasource.driverClassName
property specifies the driver class name of the database. The spring.datasource.username
and spring.datasource.password
properties specify the username and password of the database.
We can also configure the H2 console in the application.properties
file.
spring.h2.console.enabled=true
spring.h2.console.path=/h2
The spring.h2.console.enabled
property enables the H2 console. The spring.h2.console.path
property specifies the path of the H2 console.
Accessing the H2 Console
Once the H2 database is configured, we can access the H2 console by navigating to the URL http://localhost:8080/h2
. This will open the H2 console in the browser.
We can use the H2 console to view and manipulate the data stored in the database.
Summary
In this article, we learned how to configure an H2 database in a Spring Boot application. We also learned how to access the H2 console to view and manipulate the data stored in the database.
'Development' 카테고리의 다른 글
머신 러닝 용 플러터 사용 : Tensorflow Lite 및 Flutter 소개 (0) | 2023.03.01 |
---|---|
UX/UI 설계에서 사용자 연구의 중요성 : 팁 및 기술 (0) | 2023.03.01 |
Flutter for Web : Dart and Flutter를 사용하여 프로그레시브 웹 앱 구축 (0) | 2023.03.01 |
개요 스프링 부팅 테스트 (0) | 2023.03.01 |
일상 생활에서 인공 지능의 미래 (0) | 2023.03.01 |