<aside> 📖
학습 목표
JPA를 활용하기 위한 Spring Boot 프로젝트의 환경 구성을 단계별로 설명합니다.
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' // 테스트
}
💡 실무 팁
- JPA는
spring-boot-starter-data-jpa하나로 충분.- PostgreSQL 버전은 DB 서버 버전과 맞추는 것이 안정적.
src/main/resources/
├── application.yml
└── static/
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 포맷팅 가독성
💡 실무 팁
- 운영 환경에서는 ddl-auto는
none으로 변경.- URL 포트, DB명, 계정정보는 보안상 환경변수로 관리.
| 설정 | 설명 |
|---|---|
ddl-auto |
스키마 자동 생성/수정 방식 |
show-sql |
실행되는 SQL 출력 |
format_sql |
SQL을 보기 좋게 포맷팅 |
driver-class-name |
PostgreSQL 드라이버 클래스 지정 |
| 옵션 | 설명 |
|---|---|
| none | 스키마 자동 변경 안함 (운영) |
| update | 변경 사항만 반영 (개발용) |
| create | 매번 새로 생성 |
| create-drop | 종료 시 제거 (테스트용) |