From c628b9b01a0438ee1c138ce8c30bdf05a973ca2b Mon Sep 17 00:00:00 2001 From: l-wanderer01 Date: Sun, 4 May 2025 20:51:55 +0900 Subject: [PATCH] =?UTF-8?q?[feat]=20PostgreSQL=20=EC=97=B0=EA=B2=B0=20?= =?UTF-8?q?=EB=B0=8F=20application.yml,=20build.gradle=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/pirocheck/.gitignore | 3 +++ backend/pirocheck/build.gradle | 15 +++++++++++++++ .../backend/pirocheck/PirocheckApplication.java | 12 ++++++++++++ .../src/main/resources/application.properties | 1 - .../pirocheck/src/main/resources/application.yml | 12 ++++++++++++ 5 files changed, 42 insertions(+), 1 deletion(-) delete mode 100644 backend/pirocheck/src/main/resources/application.properties create mode 100644 backend/pirocheck/src/main/resources/application.yml diff --git a/backend/pirocheck/.gitignore b/backend/pirocheck/.gitignore index c2065bc..768f475 100644 --- a/backend/pirocheck/.gitignore +++ b/backend/pirocheck/.gitignore @@ -35,3 +35,6 @@ out/ ### VS Code ### .vscode/ + +### 환경 변수 ### +.env \ No newline at end of file diff --git a/backend/pirocheck/build.gradle b/backend/pirocheck/build.gradle index d57d42b..db75dba 100644 --- a/backend/pirocheck/build.gradle +++ b/backend/pirocheck/build.gradle @@ -29,6 +29,21 @@ dependencies { annotationProcessor 'org.projectlombok:lombok' testImplementation 'org.springframework.boot:spring-boot-starter-test' testRuntimeOnly 'org.junit.platform:junit-platform-launcher' + + // REST API 사용을 위해 반드시 필요 + implementation 'org.springframework.boot:spring-boot-starter-web' + + // DTO에서 @Valid 사용 시 필요 + implementation 'org.springframework.boot:spring-boot-starter-validation' + + // PostgreSQL + runtimeOnly 'org.postgresql:postgresql' + + // 환경변수 관리 + implementation 'io.github.cdimascio:java-dotenv:5.2.2' + + // Swagger + implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.8.6' } tasks.named('test') { diff --git a/backend/pirocheck/src/main/java/backend/pirocheck/PirocheckApplication.java b/backend/pirocheck/src/main/java/backend/pirocheck/PirocheckApplication.java index 96ad2c4..b7e39e5 100644 --- a/backend/pirocheck/src/main/java/backend/pirocheck/PirocheckApplication.java +++ b/backend/pirocheck/src/main/java/backend/pirocheck/PirocheckApplication.java @@ -2,11 +2,23 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import io.github.cdimascio.dotenv.Dotenv; @SpringBootApplication public class PirocheckApplication { public static void main(String[] args) { + + // .env 파일 로드 + Dotenv dotenv = Dotenv.configure() + .directory("./") // .env 파일 경로 설정 (기본: 프로젝트 루트) + .load(); + + // 환경변수를 시스템 프로퍼티에 추가 + dotenv.entries().forEach(entry -> + System.setProperty(entry.getKey(), entry.getValue()) + ); + SpringApplication.run(PirocheckApplication.class, args); } diff --git a/backend/pirocheck/src/main/resources/application.properties b/backend/pirocheck/src/main/resources/application.properties deleted file mode 100644 index 5aa603d..0000000 --- a/backend/pirocheck/src/main/resources/application.properties +++ /dev/null @@ -1 +0,0 @@ -spring.application.name=pirocheck diff --git a/backend/pirocheck/src/main/resources/application.yml b/backend/pirocheck/src/main/resources/application.yml new file mode 100644 index 0000000..656f19b --- /dev/null +++ b/backend/pirocheck/src/main/resources/application.yml @@ -0,0 +1,12 @@ +spring: + datasource: + url: jdbc:postgresql://${DB_HOST}:${DB_PORT}/${DB_NAME} + username: ${DB_USER} + password: ${DB_PASSWORD} + jpa: + hibernate: + ddl-auto: update + show-sql: true + properties: + hibernate: + format_sql: true \ No newline at end of file