hard-coding 을 ν†΅ν•΄μ„œ λͺ¨λ“  값듀을 static ν•˜κ²Œ app 에 μ‚¬μš©ν•˜λŠ” 것은 맀우 μœ μ—°ν•˜μ§€ λͺ»ν•˜λ‹€. λ”°λΌμ„œ app 을 configurable ν•˜κ²Œ λ§Œλ“€ ν•„μš”κ°€ μžˆλ‹€.

μ΄λ•Œ, application.properties νŒŒμΌμ—μ„œ custom properties λ₯Ό μ •μ˜ν•  수 μžˆλ‹€. μ΄λ ‡κ²Œ λ§Œλ“€μ–΄μ§„ properties 듀은 @Value annotation 을 μ‚¬μš©ν•˜μ—¬ app μ—μ„œ ν•΄λ‹Ή 데이터λ₯Ό μ ‘κ·Ό κ°€λŠ₯ν•˜κ²Œ λ§Œλ“€ 수 μžˆλ‹€. μ•žμ„œ Application Properties 에 λŒ€ν•˜μ—¬ μ„€λͺ…ν•œ κ²ƒμ²˜λŸΌ 말이닀.

Spring Boot Properties

application.properties λ₯Ό ν†΅ν•˜μ—¬ Spring Boot 섀정도 ꡬ성할 수 μžˆλ‹€. Server Port, Context Path, Actuator, Security 등을 μ„€μ •ν•  수 μžˆλ‹€.

λͺ¨λ“  Spring Boot Properties λŠ” Spring Boot Properties λ¬Έμ„œ μ—μ„œ 확인할 수 μžˆλŠ”λ°, 1000κ°œκ°€ λ„˜κΈ° λ•Œλ¬Έμ— property λ₯Ό 선택함에 μžˆμ–΄μ„œ 어렀움이 μžˆμ„ 수 μžˆλ‹€. κ·ΈλŸ¬λ‚˜ μœ„μ™€ 같이 8개의 그룹으둜 rough ν•˜κ²Œ λΆ„λ₯˜λ˜μ–΄ 있기 λ•Œλ¬Έμ—, ν•„μš”ν•œ 그룹에 λŒ€ν•˜μ—¬ λΆ„μ„ν•˜κ³  ν•„μš”ν•œ property λ₯Ό μ„ νƒν•˜λ©΄ λœλ‹€.

μ—¬λŸ¬κ°œμ˜ group μ€‘μ—μ„œ λͺ‡ 개만 μ‚΄νŽ΄λ³΄μž.

Core Properties
# Log levels serverity mapping
logging.level.org.springframework=DEBUG
logging.level.org.hibernate=TRACE
logging.level.com.lucvs=INFO
 
# Log file name
logging.file.name=sample.log
logging.file.path=/sample

Core Properties μ—μ„œλŠ” Spring Boot 의 μ‹€ν–‰ ν™˜κ²½, logging, message 처리, thread 관리 λ“± 핡심적인 κΈ°λŠ₯을 κ΅¬μ„±ν•˜λŠ” 데에 ν™œμš©λœλ‹€.

예λ₯Ό λ“€μ–΄ logging 의 경우 logging level 을 μœ„μ™€ 같이 μ§€μ •ν•  수 μžˆλŠ”λ°, TRACE, DEBUG, INFO, WARN, ERROR, FATAL, OFF 둜 ν•„μš”ν•œ λͺ©μ μ— 따라 μ‘°μ •ν•  수 μžˆλ‹€. μ €μž₯λ˜λŠ” log 파일의 이름 및 κ²½λ‘œλ„ λͺ…μ‹œμ μœΌλ‘œ μ§€μ •ν•  수 μžˆλ‹€.

Web Properties
# HTTP server port
server.port=7070
 
# Context path of the application
server.servlet.context-path=/sample
 
# Default HTTP session time out
server.servlet.session.timeout=15m

Web Properties μ—μ„œλŠ” web application κ³Ό κ΄€λ ¨λœ 섀정을 λ‹΄λ‹Ήν•œλ‹€.

예λ₯Ό λ“€μ–΄, μœ„μ™€ 같이 server 의 port 번호λ₯Ό μ§€μ •ν•˜κ±°λ‚˜, Context Path λ₯Ό λͺ…μ‹œμ μœΌλ‘œ λ³€κ²½ν•˜κ±°λ‚˜, session 의 timeout μ‹œκ°„μ€ default 인 30λΆ„μ—μ„œ μ›ν•˜λŠ” μ‹œκ°„μœΌλ‘œ λ°”κΏ€ 수 μžˆλ‹€.

Actuator Properties
# Endpoints to include by name or wildcard
management.endpoints.web.exposure.include=*
 
# Endpoints to exclude by name or wildcard
management.endpoints.web.exposure.include=health,info
 
# Base path for actuator endpoints
management.endpoints.web.base-path=/actuator

Actuator Properties μ—μ„œλŠ” Accessing Endpoints λΆ€λΆ„μ—μ„œ λ³Έ κ²ƒμ²˜λŸΌ, endpoints λ₯Ό μΆ”κ°€ 및 μ œμ™Έν•˜κ±°λ‚˜ Actuator endpoints 의 base path λ₯Ό μ§€μ •ν•  수 μžˆλ‹€.

Security Properties
# Default user name
spring.security.user.name=admin
 
# Password for default user
spring.security.user.password=secret

Security Properties μ—μ„œλŠ” κΈ°λ³Έ 인증 μ„€μ •μ΄λ‚˜ CSRF 보호 ν™œμ„±ν™” λ“±μ˜ κΈ°λŠ₯을 μ„€μ •ν•  수 μžˆλ‹€. μœ„μ˜ μ˜ˆμ‹œμ—μ„œλŠ” default μ‚¬μš©μžμ˜ μ΄λ¦„μ΄λ‚˜ λΉ„λ°€λ²ˆν˜Έλ₯Ό μ„€μ •ν•  수 μžˆλ‹€λŠ” 것을 보여쀀닀. κ·ΈλŸ¬λ‚˜ μ΄λŠ” μ•„μ£Ό 기본적인 μ„€μ •λ§Œ μ œκ³΅ν•˜κΈ° λ•Œλ¬Έμ— μ‹€μ œ publication λ‹¨κ³„μ—μ„œλŠ” μ‚¬μš©μ„ μ§€μ–‘ν•˜λŠ” 것이 λ°”λžŒμ§ν•˜λ‹€.

이에 λ‹¨μˆœνžˆ properties μ—μ„œ λΉ„λ°€λ²ˆν˜Έλ§Œ μ„€μ •ν•˜λŠ” 것이 μ•„λ‹ˆλΌ, 더 λ‚˜μ•„κ°€ DB λ₯Ό μ‚¬μš©ν•˜μ—¬ security info λ₯Ό ν™•μΈν•˜μ—¬ μ‚¬μš©μž 인증을 μ§„ν–‰ν•˜λŠ” 방법, μ•”ν˜Έν™”λœ λΉ„λ°€λ²ˆν˜Έλ₯Ό μ‚¬μš©ν•˜λŠ” 방법 λ“± 더 κ³ λ„ν™”λœ λ³΄μ•ˆ μ „λž΅μ„ μ‚¬μš©ν•  수 μžˆλ‹€.

Data Properties
# JDBC URL of the database
spring.datasource.url=jdbc:mysql://localhost:3306/mydb
 
# Login username of the database
spring.datasource.username=scott
 
# Login password of the database
spring.datasource.password=tiger

Data Properties μ—μ„œλŠ” Database μ—°κ²° 및 데이터 μ²˜λ¦¬μ™€ κ΄€λ ¨λœ μ„€μ •κ³Ό κ΄€λ ¨λ˜μ–΄ μžˆλ‹€.

Etcetra

이외에도, Integration Properties λŠ” messaging μ΄λ‚˜ μ™ΈλΆ€ μ‹œμŠ€ν…œκ³Όμ˜ 톡합을 μœ„ν•œ κΈ°λŠ₯, Devtools Properties λŠ” 개발 ν™˜κ²½μ—μ„œ νŽΈλ¦¬ν•œ κΈ°λŠ₯을 μ œκ³΅ν•˜λŠ” κΈ°λŠ₯, Testing Properties λŠ” ν…ŒμŠ€νŠΈ ν™˜κ²½μ—μ„œ μ‚¬μš©ν•˜λŠ” κΈ°λŠ₯을 λ‹΄λ‹Ήν•œλ‹€.