jwt 비밀키 생성
openssl rand -hex 64

application.yml 만들기
server:
port: 80
// 랜덤으로 만든 비밀키를 password에 넣어준다.
jwt:
password: ${JWT_SECRET_KEY:77d1b474a0920ab13e44a05170117cf0e809bad5c554d19020a95b45e9e2fb95893b8b149382e294d78fdb8e5aa2ae266b5797d985f5dc127366d2a50ec3938e}
//스프링 세팅
spring:
data:
redis:
host: localhost
port: 6379
// postgresql 세팅
datasource:
driver-class-name: org.postgresql.Driver
url: ${POSTGRES_DB_JDBC_URL:jdbc:postgresql://localhost:5432/postgres}
username: ${POSTGRES_DB_USERNAME:root}
password: ${POSTGRES_DB_PASSWORD:root}
// jpa 세팅
jpa:
//flyway에서 자꾸 에러띄워서 주석처리함
# hibernate:
# ddl-auto: validate
show-sql: true
database: postgresql
database-platform: org.hibernate.dialect.PostgreSQLDialect
open-in-view: false
// 디비 마이그레이션 도구
flyway:
enabled: true
baseline-on-migrate: true
locations: classpath:/db/migration # ???
schemas: study_basic
// sql 세팅
sql:
init:
platform: postgres
application-local.yml 만들기
server:
port: 8080
logging:
level:
root: DEBUG
com.example.study: DEBUG
com.zaxxer.hikari: TRACE
docker-compose.yml 만들기
version: "3"
services:
studytest_postgres14_proto:
image: postgres:14
container_name: sestest_postgres14_rdb_proto
environment:
TZ: Asia/Seoul
POSTGRES_DB: "${POSTGRES_DB_NAME}" #
POSTGRES_USER: "${POSTGRES_DB_USERNAME}" #
POSTGRES_PASSWORD: "${POSTGRES_DB_PASSWORD}" #
POSTGRES_INITDB_ARGS: '--encoding=UTF-8 --lc-collate=C --lc-ctype=C'
ports:
- 5432:5432
volumes:
- sticky_volume:/var/lib/postgresql/data
- ./db/initdb.d:/docker-entrypoint-initdb.d:ro
env_file:
- .env
study_redis_proto:
image: redis:7.0
container_name: ses_redis7_proto
ports:
- 6379:6379
volumes:
- sticky_volume:/redis/data
- ./config/redis.conf:/usr/local/conf/redis.conf
# 컨테이너에 docker label을 이용해서 메타데이터 추가
labels:
- "name=redis"
- "mode=standalone"
# 컨테이너 종료시 재시작 여부 설정
restart: always
command: redis-server /usr/local/conf/redis.conf
volumes:
sticky_volume:
.env 파일을 만들어 .yml 에 필요한 값을 지정해준다.
POSTGRES_DB_NAME=postgres
POSTGRES_DB_USERNAME=root
POSTGRES_DB_PASSWORD=root
POSTGRES_DB_JDBC_URL=jdbc:postgresql://localhost:5432/postgres
build.grdle 추가해준다.
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
// Base
implementation 'org.springframework.boot:spring-boot-starter'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
implementation 'org.springframework.boot:spring-boot-starter-validation'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
// Security
implementation 'org.springframework.boot:spring-boot-starter-security'
testImplementation 'org.springframework.security:spring-security-test'
// Jwt
implementation 'io.jsonwebtoken:jjwt-api:0.11.5'
implementation 'io.jsonwebtoken:jjwt-impl:0.11.5'
implementation 'io.jsonwebtoken:jjwt-gson:0.11.5'
compileOnly "org.springframework.boot:spring-boot-starter-security"
// Lombok
compileOnly 'org.projectlombok:lombok'
testCompileOnly 'org.projectlombok:lombok'
// Logging
implementation 'org.apache.logging.log4j:log4j-api:2.19.0'
implementation 'org.apache.logging.log4j:log4j-core:2.19.0'
// JSON
implementation 'com.google.code.gson:gson:2.10.1'
// DB
runtimeOnly 'org.postgresql:postgresql'
// Flyway
implementation 'org.flywaydb:flyway-core'
// Map Struct
implementation 'org.mapstruct:mapstruct:1.5.3.Final'
// AP(Annotation Processor)
annotationProcessor 'org.projectlombok:lombok'
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
annotationProcessor 'org.mapstruct:mapstruct-processor:1.5.3.Final'
annotationProcessor 'org.projectlombok:lombok-mapstruct-binding:0.2.0'
testAnnotationProcessor 'org.projectlombok:lombok'
//log
implementation 'org.apache.logging.log4j:log4j-api:2.19.0'
implementation 'org.apache.logging.log4j:log4j-core:2.19.0'
}