Spring Boot์ ์ค์ ์ฌํญ๋ค์ application.properties์ ๊ธฐ์ ๋ผ์๋ค. Pet Clinic์ application.properties์์๋ ๋ค์๊ณผ ๊ฐ์ ์ค์ ๋ค์ด ์กด์ฌํ๋ค. ์ฃผ์ํ ์ ์ build.gradle์ด๋ pom.xml์ ๊ด๋ จ ๋ชจ๋์ ๋ํ ์์กด์ ์ค์ ํด์ผ ์ฌ์ฉํ ์ ์๋ค๋ ์ ์ด๋ค.
๋ฐ์ดํฐ๋ฒ ์ด์ค ๊ด๋ จ ์ฌํญ๋ค์ ์ค์ ํ๋ค. ์ด์ ๊ด๋ จ๋ ๊ธ์ ๋ฐ๋ก ์์ฑํ ์์ ์ด๋ค.
database=h2
spring.sql.init.schema-locations=classpath*:db/${database}/schema.sql
spring.sql.init.data-locations=classpath*:db/${database}/data.sql
๊ธฐ๋ณธ์ ์ผ๋ก H2 DB๋ฅผ ์ฌ์ฉํ๋ค. ๊ฐ๊ฐ schema.sql, data.sql์ ๊ฒฝ๋ก๋ฅผ ์ง์ ํด์ค๋ค. ์ดํ๋ฆฌ์ผ์ด์ ์ ์์ํ ๋ schema.sql, data.sql์ ์ฌ์ฉํ์ฌ ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ์ด๊ธฐํํ๋ค.
ํ ํ๋ฆฟ ์์ง์ ์ค์ ํ๋ค. Pet Clinic์์๋ Thymeleaf๋ฅผ ์ฌ์ฉํ๋ค.
spring.thymeleaf.mode=HTML
JPA ๊ด๋ จ ์ค์ ์ด๋ค.
spring.jpa.hibernate.ddl-auto=none
spring.jpa.open-in-view=true
JPA๋ฅผ ์ฌ์ฉํ ๋ ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ์ด๊ธฐํํ๋ ์ ๋ต์ ๊ดํ ์ค์ ๊ฐ์ด๋ค. ์ต์ ๊ฐ์ผ๋ก none, validate, update, create, create-drop ๋ฑ์ด ์๋ค.
์ค์ ์ด์ํ๋ ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ create/create-drop/update๋ฅผ ์ฌ์ฉํ๋ฉด ์ ๋๋ค. create๋ update๋ ๊ฐ๋ฐ ์ด๊ธฐ์, ํ ์คํธ ์๋ฒ์์๋ update๋ validate๋ฅผ ์ฌ์ฉํ๊ณ , ์ค์ ๋ฐฐํฌ ์์ validate๋ none์ ์ฌ์ฉํ๋ค๊ณ ํ๋ค.
์์์ฑ ์ปจํ ์คํธ์ ์ง์ ๋ฒ์๋ฅผ ์ค์ ํ๋ ์ต์ ์ด๋ค. ๊ด๋ก์ OSIV๋ผ๊ณ ํ๋ค. ์ต์ ๊ฐ์ผ๋ก true/false ๋ ๊ฐ์ง๊ฐ ์กด์ฌํ๋ค. ์์์ฑ ์ปจํ ์คํธ์ ์ง์ ๋ฒ์๋ฅผ ํธ๋์ญ์ ๋ฒ์๋ก ํ์ ํ ๊ฒ์ธ์ง(false ์ต์ ) ํธ๋์ญ์ ๋ฒ์ ๋์ด์๊น์ง ์ง์ํ ๊ฒ์ธ์ง(true ์ต์ )๋ฅผ ๊ฒฐ์ ํ๋ค. Pet Clinic์์ true ์ต์ ์ ์ฃผ๊ณ ์๋ค.
์คํ๋ง์ ๋ฉ์์ง๋ฅผ ์ฌ์ฉํ๊ธฐ ์ํ ์ค์ ์ด๋ค.
spring.messages.basename=messages/messages
๋ฉ์์ง์ ์ฌ์ฉํ ํ์ผ์ ์ง์ ํด์ค๋ค. Pet Clinic์ ๊ฒฝ์ฐ src/main/resources์ ํ์์ messages/messages.properties ํ์ผ์ ์ด์ฉํ๋ค.
Spring์ด๋ผ๋ฉด ResourceBundleMessageSource๋ฅผ ์ง์ ๋น์ ๋ฑ๋กํด์ฃผ์ด์ผ ์ธ ์ ์์ง๋ง, Spring Boot์ ๊ฒฝ์ฐ ์ด๋ฏธ ๋ฑ๋ก์ด ๋ผ ์์ด application.properties์์ ๋ฉ์์ง๋ก ์ฌ์ฉํ ํ์ผ๋ง ์ง์ ํด์ฃผ๋ฉด ์ฌ์ฉํ ์ ์๋ค.
messages-kr.properties ๋ฑ์ ํ์ผ์ ์ถ๊ฐํ๋ฉด ํด๋ผ์ด์ธํธ์ ์ธ์ด ์ค์ ์ ๋ฐ๋ผ ๋ฉ์์ง๋ฅผ ๋ณ๊ฒฝํ ์ ์๋ค.
Acturator๋ ์ดํ๋ฆฌ์ผ์ด์ ๋ชจ๋ํฐ๋ง์ ์ํด Spring Boot์์ ์ ๊ณตํ๋ ์์ฒด ๋ชจ๋ํฐ๋ง ํด์ด๋ค. ์ดํ๋ฆฌ์ผ์ด์ ๋ชจ๋ํฐ๋ง์ ์ํ endpoint๋ฅผ ์ค์ ํ ์ ์๋ค. endpoint๋ ๋ชจ๋ํฐ๋ง ์์ ์ ๋๋ก ์ดํดํ๋ฉด ๋ ๊ฒ ๊ฐ๋ค. ๋ค์๊ณผ ๊ฐ์ด ์ ๋ ฅํ๋ฉด ๋ชจ๋ endpoint์ ๋ํ ๋ชจ๋ํฐ๋ง์ ์ ๊ณตํ๋ค๋ ๋ป์ด๋ค.
management.endpoints.web.exposure.include=*
ํ์ง๋ง ์ด์ฒ๋ผ ๋ชจ๋ ์ ๋ณด๋ฅผ ๋ชจ๋ํฐ๋งํ ์ ์๊ฒ ์ค์ ํ๋ฉด ๋ฏผ๊ฐํ ์ ๋ณด์ ์ ๊ทผํ ์ ์๊ธฐ ๋๋ฌธ์ ์ค์ ๋ฐฐํฌํ๊ฒฝ์์๋ ํ์ํ ์ ๋ณด๋ง์ ๋ชจ๋ํฐ๋งํ ์ ์๋๋ก ์ ์ ํ ์ค์ ์ด ํ์ํ๋ค. ๊ถํ์ด ์๋ ์ฌ์ฉ์๋ง ์ ๊ทผํ ์ ์๋๋ก ํ๋ ์กฐ์น๋ ๊ณ ๋ คํ ์ ์๋ค. ๋ํ, ์ค์ ์ด์ ์ํฉ์์ ์ด๋ฅผ ํ์ฉํ๊ธฐ ์ํด์๋ DB๋ ํ์ผ์ ์ ์ฅํ๋ ๊ฒ์ด ์ข๋ค.
์ฝ์์ ๋ณด์ฌ์ง ๋ก๊ทธ๋ฅผ ์ค์ ํ๋ ์ต์ ์ด๋ค.
logging.level.org.springframework=INFO
#logging.level.org.springframework.web=DEBUG
#logging.level.org.springframework.context.annotation=TRACE
์ด์ฒ๋ผ ์ค์ ํ๋ฉด ๊ธฐ๋ณธ์ ์ผ๋ก INFO level์ ๋ก๊ทธ๋ง ์ถ๋ ฅํ๊ฒ ํ๊ณ , ํ์์ ๋ฐ๋ผ ์ฃผ์์ ํด์ ํด์ ์ฌ์ฉํ ์ ์๋๋ก ํ๋ค. ์ด๋ Spring Boot์์ ๊ธฐ๋ณธ์ ์ผ๋ก ์ ๊ณตํ๋ Logback์ ์ด์ฉํ ์ค์ ์ด๋ค. ํ์์ ๋ฐ๋ผ ๋ค๋ฅธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฌ์ฉํ ์ ์์ง๋ง Logback๋ ๋ค๋ฅธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ ๋ค์ง์ง ์์ ๋งํผ ๊ด์ฐฎ์ ์ฑ๋ฅ์ ๊ฐ์ง๊ณ ์๋ค๊ณ ํ๋ค.
๋ก๊ทธ ๋ ๋ฒจ์ ERROR - WARN - INFO - DEBUG - TRACE์ ๋ค์ฏ ๋จ๊ณ๊ฐ ์๋ค.
ํ์์ ๋ฐ๋ผ ํ์ผ๋ก ์ ์ฅํ๋ ๊ฒ๋ ์ง์ํ์ง๋ง, Pet Clinic์์๋ ๋ฐ๋ก ํ์ผ๋ก ์ ์ฅํ๋๋ก ์ค์ ํ์ง ์์๋ค.
spring.web.resources.cache.cachecontrol.max-age=12h
์ ์ ์์๋ค์ ์บ์ ์ ํจ๊ธฐ๊ฐ์ ์ค์ ํ๋ ์ต์ ์ด๋ค. ๊ธฐ๋ณธ ๋จ์๋ ์ด ๋จ์์ง๋ง ์์ ์ค์ ์ 12h์ธ ๊ฑธ ๋ณด๋ 12์๊ฐ์ธ ๊ฒ ๊ฐ๋ค. Http ์๋ต์ ํฌํจ๋๋ Cache-control ํค๋์ ๋ฐ๋ผ ๋ฐ์ ๋ฆฌ์์ค์ ์๋ช ์ฃผ๊ธฐ๊ฐ ๊ฒฐ์ ๋๋ค๊ณ ํ๋ค. ์์ ์ค์ ์ ๊ธฐ๋ณธ ์บ์ ์ ์ฑ ์ ๊ฒฐ์ ํ๋ ์ต์ ์ด๋ค. ์บ์์ ์ ํจ๊ธฐ๊ฐ์ด ๋๋ฌด ์งง์ผ๋ฉด ์๋ฒ์ ๋ฆฌ์์ค ์์ฒญ์ ๋๋ฌด ์์ฃผ ํ๊ฒ ๋์ด ์๋ฒ์ ๋ถํ๊ฐ ์ฌ ์ ์๊ณ , ์ ํจ๊ธฐ๊ฐ์ด ๋๋ฌด ๊ธธ๋ฉด ๋ง๋ฃ๋ ๋๊น์ง ๋ธ๋ผ์ฐ์ ์ ๋ฆฌ์์ค๊ฐ ๋จ์์๊ณ ์ด๋ฅผ ์ง์ฐ๋ ๊ฒ ์ด๋ ต๊ธฐ ๋๋ฌธ์ ์ ์ ํ max-age์ ์ค์ ์ด ์ค์ํ๋ค.
Pet Clinic์ ์ค์ ํ์ผ์ ์ดํด๋ดค๋ค. ์ด ํ์ผ ํ๋๋ฅผ ํด์ํ๋๋ฐ๋ ์์ญ๋ฒ์ ๊ฒ์์ด ํ์ํ๋ค. ๋ฌด์ง์ฑ์ผ๋ก ํด๋ก ์ฝ๋ฉํ๋ฉด ๋ชจ๋ฅผ ๊ฒ๋ค์ด๊ฒ ์ง.. 'ํ๋ํ๋ ์์๊ฐ๋ค ๋ณด๋ฉด ์ธ์ ๊ฐ ๋์์ด ๋๊ฒ ์ง'๋ผ๊ณ ์๊ฐํ๋ฉฐ ๋ง์น๊ฒ ๋ค. ์ด์ ๋ณด๋ค ๋์ ์ค๋, ๊ทธ๋ฆฌ๊ณ ์ค๋๋ณด๋ค ๋์ ๋ด์ผ์ด ๋๊ธธ ๋ฐ๋ผ๋ฉฐ...
** ์์ธํ ๋ด์ฉ์ ์ฐธ๊ณ ๋งํฌ์ ์ ํ์๋ค. ์ฐธ๊ณ ๋งํฌ์ ๋ด์ฉ์ ๊ทธ๋๋ก ๊ฐ์ ธ์ค๊ฑฐ๋ ๋ด๊ฐ ๋ ์ ๋ฆฌํ๋ ๊ฑด ์์๊ฐ ์๋ ๊ฒ ๊ฐ์ ํ์ํ ๋ถ๋ถ๋ค๋ง ์กฐ๊ธ์ฉ ๋ด๊ฐ ์ดํดํ ๋๋ก ํ์ํ ๋งํผ๋ง ์ ์๋ค. ์ฐธ๊ณ ๋งํฌ๋ฅผ ํ์ฉํ์ฌ ๋ ๊น๊ฒ ํ์ตํ๋ ๊ฒ๋ ์ข์ ๊ฒ ๊ฐ๋ค.
** ์คํ, ์๋ชป๋ ๋ด์ฉ ์ง์ ํ์
Spring Boot doc
https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.spring-application
ํ์๋ฆฌํ ์ค๋ช
https://jhhan009.tistory.com/12
JPA ์ค๋ช
[ hibernate.ddl-auto ]
https://haservi.github.io/posts/spring/hibernate-ddl-auto/
https://smpark1020.tistory.com/140
[ open-in-view ]
https://gracelove91.tistory.com/100
Acturator ์ค๋ช
https://sabarada.tistory.com/23
https://techblog.woowahan.com/9232/
Cache-Control ์ค๋ช
https://toss.tech/article/smart-web-service-cache
https://hudi.blog/http-cache/