실전! Querydsl

Ch01. 프로젝트 환경 설정 - H2 데이터베이스 설치, 스프링 부트 설정(JPA, DB)

webmaster 2021. 12. 29. 15:19
728x90

H2 DataBase 설치

https://www.h2database.com/html/main.html

 

H2 Database Engine

H2 Database Engine Welcome to H2, the Java SQL database. The main features of H2 are: Very fast, open source, JDBC API Embedded and server modes; in-memory databases Browser based Console application Small footprint: around 2.5 MB jar file size     Supp

www.h2database.com

  • 다운로드 및 설치
  • h2 데이터베이스 버전은 스프링 부트 버전에 맞춘다.
  • 데이터베이스 파일 생성 방법
    • jdbc:h2:~/querydsl (최소 한번)
    • ~/querydsl.mv.db 파일 생성 확인
    • 이후부터는 jdbc:h2:tcp://localhost/~/querydsl 이렇게 접속

스프링 부트 설정 - JPA, DB

Application.yml 파일에 스프링 관련 설정을 적는다.

spring:
  datasource:
    url: jdbc:h2:tcp://localhost/~/querydsl
    username: sa
    password:
    driver-class-name: org.h2.Driver

  jpa:
    hibernate:
      ddl-auto: create
    properties:
      hibernate:
        # show_sql: true
        format_sql: true
        
logging.level:
  org.hibernate.SQL: debug
# org.hibernate.type: trace
  • spring.jpa.hibernate.ddl-auto: create
    • 이 옵션은 애플리케이션 실행 시점에 테이블을 drop 하고, 다시 생성한다.
  • 외부 라이브러리 추가

외부 라이브러리 의존성 추가

쿼리의 로그의 파라미터를 더 상세히 볼 수 있다.

728x90