Skip to content

Commit

Permalink
Spring Boot 환경을 추가하라
Browse files Browse the repository at this point in the history
  • Loading branch information
jihwooon committed Mar 24, 2024
1 parent e236adb commit 7e7c9d8
Show file tree
Hide file tree
Showing 142 changed files with 721 additions and 0 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
37 changes: 37 additions & 0 deletions server-spring/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
HELP.md
.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
out/
!**/src/main/**/out/
!**/src/test/**/out/

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/

### VS Code ###
.vscode/
8 changes: 8 additions & 0 deletions server-spring/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM openjdk:17 AS builder

COPY . .
RUN ["./gradlew","assemble"]

FROM openjdk:17
COPY build/libs/core-0.0.1-SNAPSHOT.jar app.jar
CMD ["java", "-jar", "core-0.0.1-SNAPSHOT.jar"]
75 changes: 75 additions & 0 deletions server-spring/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Book Store SpringBoot

이는 Spring Boot 구축된 서점 애플리케이션용 REST API입니다.
이는 도서에 대한 CRUD 작업을 제공하고 다음 기능에 대한 API 엔드포인트를 포함합니다.

## Tech Stack
- SpringBoot 3.2.3
- Java zulu 17.0.9
- Gradle 8.4
- JPA
- H2 Database
- MySQL 8

## Getting Started
- Repository 복제합니다.
- IDE(통합 개발 환경) 에서 프로젝트를 열고 Maven Dependencies를 다운로드 받습니다.
-`application.yaml` 파일을 열고 `spring.datasource.url`을 수정합니다.
- Test를 실행합니다.
- 데이터베이스에 데이터가 추가 여부를 확인합니다.
- Spring Boot를 실행합니다.

## Database Setting
- **Dev Environment**
로컬 개발 시 MySQL 데이터베이스를 사용합니다.
MySQL은 Docker를 실행해야 사용 할 수 있습니다.
> :: Docker 환경 설정은 아래에 설명 되어 있습니다.
```yaml
spring:
datasource:
url: jdbc:mysql://localhost:3306/metlife?serverTimezone=UTC&characterEncoding=UTF-8
username: root
password: root
driver-class-name: com.mysql.cj.jdbc.Driver
```
- **Test Environment**
테스트 개발 시 H2 데이터베이스를 설치합니다.
- https://www.h2database.com/
- 스프링 부트 3.x를 사용하면 **2.1.214 버전 이상** 사용해야 한다.
- H2 데이터베이스를 실행 하기 위해서는 다음과 같이 수행합니다.
- 웹 페이지에 `jdbc:h2:~/data/dev` 수행합니다.
- `~/data/dev.mv.db` 파일 생성을 확인합니다.
- application-dev.yaml url에 `jdbc:h2:tcp://localhost/~/data/dev`를 추가합니다.
- Spring Boot를 실행합니다.

- **Prod Environment**
프로덕트 개발 시 Cloud Service Database를 `application-prod.yml`추가합니다.
```yaml
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://{Cloud Service Database}/{db명}
username: userId
password: password
```

## Deploy Setting
Spring Boot 배포 하기 전 빌드를 수행해야 합니다.

우선 `assemble`로 결과물로 조합해서 빌드합니다.
```bash
./gradlew assemble
```
test 서버 배포 실행은 다음 명령어로 수행합니다.
```bash
java -jar -Dspring.profiles.active=test build/libs/core-0.0.1-SNAPSHOT.jar
```

dev 서버 배포 실행은 다음 명령어로 수행합니다.
```bash
java -jar -Dspring.profiles.active=dev build/libs/core-0.0.1-SNAPSHOT.jar
```
prod 서버 배포 실행은 다음 명령어로 수행합니다.
```bash
java -jar -Dspring.profiles.active=prod build/libs/core-0.0.1-SNAPSHOT.jar
```
69 changes: 69 additions & 0 deletions server-spring/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
plugins {
id 'java'
id 'org.springframework.boot' version '3.2.3'
id 'io.spring.dependency-management' version '1.1.4'
}

group = 'jpa'
version = '0.0.1-SNAPSHOT'

java {
sourceCompatibility = '17'
}

configurations {
compileOnly {
extendsFrom annotationProcessor
}
}

repositories {
mavenCentral()
}

dependencies {
// Spring Boot Web
implementation 'org.springframework.boot:spring-boot-starter-web'

// Spring Cloud OpenFeign
implementation 'org.springframework.cloud:spring-cloud-starter-openfeign:4.1.0'

// Spring Boot Jpa
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
runtimeOnly 'com.h2database:h2'

// Spring Boot Validation
implementation 'org.springframework.boot:spring-boot-starter-validation'

// Mysql
implementation 'com.mysql:mysql-connector-j:8.3.0'

// Lombok
compileOnly 'org.projectlombok:lombok:1.18.16'
annotationProcessor 'org.projectlombok:lombok'

// devtools
developmentOnly 'org.springframework.boot:spring-boot-devtools'

// Junit
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.junit.jupiter:junit-jupiter'

// AssertJ
testImplementation 'org.assertj:assertj-core:3.18.1'

// Spring Boot Test
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}

// p6spy
implementation 'com.github.gavlyukovskiy:p6spy-spring-boot-starter:1.9.0'

// jjwt
implementation group: 'io.jsonwebtoken', name: 'jjwt-api', version: '0.12.3'
}

tasks.named('test') {
useJUnitPlatform()
}
Binary file added server-spring/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
23 changes: 23 additions & 0 deletions server-spring/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#
# Copyright 2012-2024 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit 7e7c9d8

Please sign in to comment.