ํฐ์คํ ๋ฆฌ ๋ทฐ
ํ๊ฒฝ๋ถ๋ฆฌ์ ํ์์ฑ
์ค์ ๋ฐฐํฌํ ์๋น์ค๋ผ๋ฉด,
๊ฐ๋ฐ ์๋ฒ์ ์ด์ ์๋ฒ๋ฅผ ๋๋ ์ ๊ด๋ฆฌํ ํ์๊ฐ ์๋ค.
์ถ๊ฐ์ ์ผ๋ก ํ
์คํธ ํ๊ฒฝ๋ ๋ถ๋ฆฌํด์ฃผ๋ฉด ์ข๊ณ ,
JPA๋ฅผ ์ฌ์ฉํ๋ค๋ฉด ddl-auto: create ๋ฅผ ์ฌ์ฉํ๋
์ด๊ธฐ ํ๊ฒฝ์ธํ
๋ ๋ถ๋ฆฌํด๋๋ฉด ์ด์ ์๋ฒ์์ create๊ฐ ์คํ๋๋
๋์ฐธ์ฌ๋ฅผ ์๋ฐฉ๊ฐ๋ฅํ๋ค.
ํ๊ฒฝ๋ถ๋ฆฌํ๋ ๋ฐฉ๋ฒ
ํ๊ฒฝ๋ถ๋ฆฌ ๋ฐฉ๋ฒ์ ์ฐพ์๋ณด๋ ํฌ๊ฒ ๋ ๊ฐ์ง์ด๋ค.
1. yml ํ์ผ ๋๋๊ธฐ
2. ํ๋์ yml ํ์ผ ์์์ ๋๋๊ธฐ
๊ธฐ๋ณธ ํ๊ฒฝ ์ธํ

JPA์ ์คํ๋ง๋ถํธ2.7.1๋ก ๊ธฐ๋ณธ ํ๊ฒฝ์ ๊ตฌ์ฑ
Entity๋ ๊ฐ๋จํ๊ฒ User ๋ฅผ ๋ง๋ค์ด๋๊ณ ,

์คํํด๋ณด๋ ํฌํธ 8080์ผ๋ก ์ ์คํ๋๊ณ ,ddl-auto: create ์ค์ ์ ๋ง๊ฒ ํ
์ด๋ธ์ด ์์ฑ๋๋ค.

db์๋ ์ ์์ฑ์ด ๋๋ค.
์ด์ ํ๊ฒฝ์ ๋ถ๋ฆฌํด๋ณด์.
yml ํ์ผ ๋๋๊ธฐ

application.yml
server:
port: 8080
spring:
profiles:
default: dev # ๊ธฐ๋ณธ ํ๊ฒฝ์ dev๋ก
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/profiledemo?serverTimezone=Asia/Seoul
username: root
password: abcd
jpa:
hibernate:
ddl-auto: update
properties:
hibernate:
format_sql: true
show-sql: true
application-create.yml
server:
port: 8081
spring:
config:
activate:
on-profile: create # ํ๊ฒฝ์ด๋ฆ์ค์
jpa:
hibernate:
ddl-auto: create
application-dev.yml
server:
port: 8082
spring:
config:
activate:
on-profile: dev
jpa:
hibernate:
ddl-auto: update
application-prod.yml
server:
port: 8083
spring:
config:
activate:
on-profile: prod
jpa:
hibernate:
ddl-auto: none
์ธ๊ฐ์ง ํ์ผ์ ๋ง๋ค์์ต๋๋ค.
๊ธฐ๋ณธ yml ์ค์ ์ ์์ฑํ ๋ด์ฉ๋ค์๊ฒ
์ถ๊ฐ๋ก profile์ ์์ฑํ ๋ด์ฉ๋ค์ด ๋ฎ์ด์ฐ๊ธฐ ๋๋ ๋ฐฉ์์ด๋ค.
์ฌ๊ธฐ์๋ port ๋ฒํธ์ ddl-auto ์ค์ ๋ง ๋ฐ๊ฟจ๋๋ฐ,
datasource ์ธํ
์ด๋ ๋ค๋ฅธ ์ค์ ๋ค๋ ์์ฑํ์ฌ ๋ฐ๊ฟ ์ ์๋ค.

์ธํ
๋ฆฌ์ ์ด์์ Edit Configurations๋ก ๋ค์ด๊ฐ์
Active profiles ๋ถ๋ถ์ ์ํ๋ profile๋ช
์ ์
๋ ฅํ๋ฉด
ํด๋น ์ธํ
์ผ๋ก ์คํ๋๋ค.

์๋ฌด ์ค์ ์์ด ์คํํ๋ฉด default๋ก ์ค์ ํด๋ dev ์ธํ
์ผ๋ก ์คํ๋๋ค.
ํฌํธ8082๋ก ์ ์คํ๋์๋ค!

์ด๋ฒ์ create ์ธํ
์ผ๋ก ์คํํด๋ณด์.
ํฌํธ 8081๋ก ์คํ๋๋ฉฐ ddl-auto: create๊ฐ ์ ์ฉ๋๋ค.

prod ์ธํ
๋ ์ ์คํ๋๋ค. (ํฌํธ 8083)
yml ํ๋๋ก ๋๋๊ธฐ
application.yml
server:
port: 8080
spring:
profiles:
default: dev # ๊ธฐ๋ณธ ํ๊ฒฝ์ dev๋ก
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/profiledemo?serverTimezone=Asia/Seoul
username: root
password: abcd
jpa:
hibernate:
ddl-auto: update
properties:
hibernate:
format_sql: true
show-sql: true
---
server:
port: 8081
spring:
config:
activate:
on-profile: create # ํ๊ฒฝ์ด๋ฆ์ค์
jpa:
hibernate:
ddl-auto: create
---
server:
port: 8082
spring:
config:
activate:
on-profile: dev
jpa:
hibernate:
ddl-auto: update
---
server:
port: 8083
spring:
config:
activate:
on-profile: prod
jpa:
hibernate:
ddl-auto: none
ํ๋์ yml ํ์ผ๋ก ๋๋๋์๋--- ๋ก ๋๋ ์ ์์ฑํ๋ฉด ๋๋ค.
yml ํ์ผ ์์ฑ๋ฒ๋ง ๋ค๋ฅผ๋ฟ ์คํํ๋ ๋ฐฉ๋ฒ์ด๋ ์คํ ๊ฒฐ๊ณผ๋ ์ฌ๋ฌ yml์ผ๋์ ๋๊ฐ์ด ํ๋ฉด๋๋ค.
ํ
์คํธ ํ๊ฒฝ ๋๋๊ธฐ

ํ
์คํธ ํ๊ฒฝ ๋๋๊ธฐ๋ test ํด๋์ resources ํด๋๋ฅผ ์์ฑํด ์ฃผ์๊ณ
application.yml ํ์ผ์ ๋ง๋ค์ด ์ฃผ์.
ํ์ผ์ ๋ง๋ค์ด๋ง ๋๋ฉด ํ ์คํธ ์คํ์ ํ ์คํธ์ฉ ํ๊ฒฝ์ธํ ์ผ๋ก ์คํ๋๋ค.
๊ทธ๋ฆฌ๊ณ JPA์ ๊ฒฝ์ฐ ํ
์คํธ application.yml์์ datasource๋ฅผ ์์ ์
๋ ฅํ์ง ์์ผ๋ฉด,
์๋์ผ๋ก H2 db๋ก ์ธํ
๋๋ค.(H2 ์์กด์ฑ ์ถ๊ฐ๋ ํด์ค์ผํจ)
๋ง๋ฌด๋ฆฌ
์คํ๋ง ๋ถํธ ์์ ๋ฒ์ 2.4์ด์ ์์๋
spring:
profiles: dev
๋ฐฉ์์ผ๋ก profile ์ด๋ฆ์ค์ ์ ํ๋ค๊ณ ํ๋ค.
- Total
- Today
- Yesterday
- ๋ฐ์ดํฐ๋ฒ ์ด์ค
- codestates
- ์ํฐ๋ ์ฑ๋ฆฐ์ง
- oracle
- VMware
- error
- preproject
- ๋ค์ด๋๋ฏนํ๋ก๊ทธ๋๋ฐ
- pyinstaller ์ค์น
- ์ ๋ณด์ฒ๋ฆฌ๊ธฐ์ฌ ์ค๊ธฐ
- sqld
- mapper
- yml ๋ถ๋ฆฌ
- doit์๊ณ ๋ฆฌ์ฆ์ ๋ฌธ
- Spring
- JSP
- ์ฐ๋ถํฌ
- PostgreSQL
- mysql ์ค์
- ๋์ปค
- modifiedAt
- ๋ ์
- Stream
- ์ฝ๋์คํ ์ด์ธ
- docker
- Java
- Til
- ๋ฐฑ์ค
- ํ๊ณ
- xml
| ์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |