H2DB 셋팅
H2DB 설치 및 셋팅
H2DB는 RDMBS(관계형 데이터 베이스)이다.
oracle, mysql 등 과는 다르게 인메모리 데이터 베이스이다.
설치 링크
H2 Database Engine (redirect)
H2 Database Engine Welcome to H2, the free SQL database. The main feature of H2 are: It is free to use for everybody, source code is included Written in Java, but also available as native executable JDBC and (partial) ODBC API Embedded and client/server mo
www.h2database.com
해당 프로젝트의 spring boot 버전에 맞는 h2를 다운받는다.
h2.bat를 실행하면 H2웹 콘솔이 열리고 기본 값으로 연결을 할 수 있다.
최초로 연결할 때는 JDBC URL을 파일로 직접 접근해서 생성 해줘야 한다.
파일로 직접 접근 => jdbc:h2:~/test
위와 같이 접근하면 데이터베이스 파일을 로컬에 만들게 된다.
계속 파일로 직접 접근하면 파일 락이 걸릴 수 있으므로 최초로 접근 후에는
원격으로 연결한다
원격 연결 => jdbc:h2:tcp://localhost/~/test
H2DB를 프로젝트에 연결하기 위해서 해줘야하는 작업이있다.
1. 의존성이 주입되어 있는지 확인(maven)
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
2. application.properties 소스 추가
# H2
spring.h2.console.enabled=true
spring.h2.console.path=/h2 // 서버 구동시 localhost:포트번호/h2 로 접속할 수 있다.
# Datasource
spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.url=jdbc:h2:~/test
spring.datasource.username=sa
spring.datasource.password=
포트 변경
h2DB 실행할 때, cmd에서 h2.bat파일 경로로 들어간 다음
\H2\bin> h2.bat -webPort 8081 -tcpPort 9091 이런식으로 구동.
SpringBoot 버전에 호환되는 H2버전 미리 확인
1. 스프링 io 사이트에 접근
Spring makes Java simple.
Level up your Java code and explore what Spring can do for you.
spring.io
2. Projects > Spring Boot 메뉴로 접근해서 LEARN탭의 원하는 버전 Reference Doc 클릭
3. Reference Doc로 들어온 후 Dependency Versions 클릭
4. 해당 Spring Boot에 맞는 라이브러리 버전들을 확인 할 수 있다.