Woopii Vyeolog

[Spring Boot] H2DB JDBC연동 본문

Spring Boot

[Spring Boot] H2DB JDBC연동

WooPii 2022. 2. 2. 20:15

● Spring boot에 H2DB Dependency 추가

1. 아래 링크로 h2db 사이트의 maven dependency 확인

http://h2database.com/html/build.html?highlight=maven&search=maven#maven2 

 

Build

  Build Portability Environment Building the Software Using Maven 2 Using Eclipse Translating Submitting Source Code Changes Reporting Problems or Requests Automated Build Generating Railroad Diagrams Portability This database is written in Java and there

h2database.com

 

2. pom.xml에 다음을 추가

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
    <groupId>com.h2database</groupId>
    <artifactId>h2</artifactId>
    <version>1.4.200</version>
</dependency>

 

3. application.yml 파일에 다음과 같이 추가

##h2.console 은 h2db 콘솔 화면에 접속이 가능하게 해주는 설정

 

spring:
    h2:
        console:
            enabled: true
            path: /h2-console

    datasource:
        driverClassName: org.h2.Driver
        #url: jdbc:h2:file:./target/h2db/db/application;DB_CLOSE_DELAY=-1
        url: jdbc:h2:mem:testdb
        username: sa
        password:

 

 

4. 프로젝트 실행 후 콘솔 접속

url =====> http://localhost:8080/h2-console

application.yml 에 적었던 설정대로 h2-console 화면에도 입력

 

5. 접속 확인

Comments