<aside> 📖

학습 목표

1. 프로젝트 설정

JPA를 활용하기 위한 Spring Boot 프로젝트의 환경 구성을 단계별로 설명합니다.

1-1. 의존성 추가 (Gradle)

build.gradle 예시 (Spring Boot 3.x 기준)

plugins {
    id 'java'
    id 'org.springframework.boot' version '3.2.5'
    id 'io.spring.dependency-management' version '1.1.4'
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa' // JPA
    implementation 'org.postgresql:postgresql:42.7.3'                     // PostgreSQL 드라이버
    implementation 'org.springframework.boot:spring-boot-starter-web'     // REST API
    testImplementation 'org.springframework.boot:spring-boot-starter-test' // 테스트
}

💡 실무 팁


1-2. 데이터소스 설정

1-2-1. 디렉토리 구조 (resources)

src/main/resources/
├── application.yml
└── static/

1-2-2. application.yml 예시

spring:
  datasource:
    url: jdbc:postgresql://localhost:5432/exampledb # DB이름 설정 필요
    username: exampleuser
    password: examplepw
    driver-class-name: org.postgresql.Driver
  jpa:
    hibernate:
      ddl-auto: update # 개발 단계는 update, 운영은 none 권장
    show-sql: true       # 실행 쿼리 확인
    properties:
      hibernate:
        format_sql: true # SQL 포맷팅 가독성

💡 실무 팁


1-3. JPA 설정 설명

설정 설명
ddl-auto 스키마 자동 생성/수정 방식
show-sql 실행되는 SQL 출력
format_sql SQL을 보기 좋게 포맷팅
driver-class-name PostgreSQL 드라이버 클래스 지정

1-3-1. ddl-auto 옵션 비교

옵션 설명
none 스키마 자동 변경 안함 (운영)
update 변경 사항만 반영 (개발용)
create 매번 새로 생성
create-drop 종료 시 제거 (테스트용)