Tools/Spring

[SpringBoot 2.7.*] H2 Jdbc 설정, schema(DDL) 및 data(DML)

하루y 2023. 9. 16. 21:06

H2 버전 조정

	<properties>
		<java.version>11</java.version>
		<!-- 2.x 최신버전에서 validation이 강화되어, 버전을 낮춰서 테스트 진행하는 것으로 보임. JJH -->
		<h2.version>1.4.196</h2.version>
	</properties>

1. 1H2 File DB 및 Memory DB 설정

2. 초기 schema(DDL) 및 data(DML) 설정

spring:
  datasource:
    # 1. H2 file DB. 어플리케이션 경로에서 생성. DB경로. AUTO_SERVER는 다중접속여부
    url:  jdbc:h2:file:./db/h2/data;AUTO_SERVER=true
    # 2. H2 file DB. ~ 는 사용자 계정아래에 DB 생성.
#    url:  jdbc:h2:~/db/h2/data;AUTO_SERVER=true
    # 3. H2 Memory DB
#    url:  jdbc:h2:mem:testdb
    driverClassName: org.h2.Driver
    username: sa
    password:
  h2:
    console:
      enabled: true
      path: /h2-console
  sql:
    init:
      mode: always
      schema-locations: classpath:/h2/schema.sql
      data-locations: classpath:/h2/data.sql
#  jpa:
#    defer-datasource-initialization: true

 

 

728x90