Spring Boot

Spring ์ดˆ๊ธฐ ์„ค์ • ์—์„œ ๋ณธ ๊ฒƒ์ฒ˜๋Ÿผ, Spring Legacy Project๋ฅผ ์ƒ์„ฑํ•  ๊ฒฝ์šฐ ๋ฐฉ๋Œ€ํ•˜๊ณ  ๋ณต์žกํ•œ ์ดˆ๊ธฐ ์„ค์ •(๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ, ์˜์กด์„ฑ ๋“ฑ)์— ์••๋„๋˜๊ธฐ ์‰ฝ๋‹ค.

SpringBoot๋Š” ์ž์ฃผ ์‚ฌ์šฉ๋˜๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์กฐํ•ฉ์„ ๋งŒ๋“ค์–ด ๋ณต์žกํ•œ ์„ค์ •์„ ์ž๋™์œผ๋กœ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•˜๋Š” Spring์˜ ๋ฐœ์ „๋œ ๋ฒ„์ „์ด๋ผ๊ณ  ์ƒ๊ฐํ•˜๋ฉด ๋œ๋‹ค.

Spring Boot ํŠน์ง•

  • ๋‚ด์žฅ ์„œ๋ฒ„๋ฅผ ํฌํ•จํ•˜๊ณ  ์žˆ๊ธฐ๋•Œ๋ฌธ์— Tomcat๊ณผ ๊ฐ™์€ WAS๋ฅผ ์ถ”๊ฐ€ํ•˜์ง€ ์•Š๊ณ ๋„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.
  • WARํŒŒ์ผ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ JARํŒŒ์ผ ํ˜•ํƒœ๋กœ ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋‹ค.

Spring Boot(Spring Starter Project)

Spring Starter Project ์ƒ์„ฑ -> ํ”„๋กœ์ ํŠธ ๋ช…, Java Version, Packaging ๋“ฑ ์„ ํƒ -> Dependency ์„ค์ •

Spring Legacy Project ์—์„œ Spring Boot Project๋กœ์˜ ๋ณ€ํ™”

Spring Legacy Project Vs SpringBoot Project

  • src/main/java : java ์†Œ์Šค ๋””๋ ‰ํ„ฐ๋ฆฌ
  • ํ”„๋กœ์ ํŠธ๋ช…Application.java : Java ์†Œ์Šค ๊ธฐ๋ฐ˜ ์Šคํ”„๋ง ํ”„๋กœ์ ํŠธ ํ™˜๊ฒฝ ์„ค์ • ํŒŒ์ผ(@Configuration). 3 ๊ณ„์ธต์˜ ํŒจํ‚ค์ง€(com.capo.testapp) ํ•˜์œ„์— ์กด์žฌํ•˜๋Š” ๋ชจ๋“  Component๋ฅผ auto scanํ•œ๋‹ค.
  • static : css, js, img ๋“ฑ ์ •์  ๋ฆฌ์†Œ์Šค๋ฅผ ๋ชจ์•„๋‘” ๋””๋ ‰ํ„ฐ๋ฆฌ
  • src/main/webapp ํ•˜์œ„์— WEB-INF/views ๋””๋ ‰ํ„ฐ๋ฆฌ๋ฅผ ์ƒ์„ฑ : jsp์™€ ๊ฐ™์€ ๋™์  ๋ฆฌ์†Œ์Šค๋ฅผ ๋ชจ์•„๋‘” ๋””๋ ‰ํ„ฐ๋ฆฌ
  • application.properties : ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ํ˜น์€ ์Šคํ”„๋ง ์„ค์ •์—์„œ ์‚ฌ์šฉํ•˜๋Š” ์—ฌ๋Ÿฌ property๋ฅผ ์ •์˜ํ•œ ํŒŒ์ผ. ๊ธฐ์กด Legacy Project์˜ db.properties, log4j.xml, web.xml, servlet-context.xml, root-context.xml ๋“ฑ์˜ ์„ค์ • ๋‚ด์šฉ์€ ์—ฌ๊ธฐ์„œ ์„ค์ •ํ•˜๋ฉด ๋œ๋‹ค.
# context path ์„ค์ •
server.servlet.context-path=/movieapp
server.port=9090

# db connection pool ์„ค์ •
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/moviedb?serverTimezone=UTC
spring.datasource.username=ssafy
spring.datasource.password=ssafy
spring.datasource.type=org.apache.commons.dbcp2.BasicDataSource

# mybatis ์„ค์ •
mybatis.mapper-locations=mapper/**/*.xml
mybatis.type-aliases-package=com.ssafy.movieapp.model.dto

# view resolver ์„ค์ •(jsp๋ฅผ ์œ„ํ•จ)
spring.mvc.view.prefix=/WEB-INF/views/
spring.mvc.view.suffix=.jsp

# logging ๋ ˆ๋ฒจ ์„ค์ •
logging.level.com.ssafy.movieapp.controller=debug
  • servletInitializer.java : WAR๋กœ ๋ฐฐํฌํ•  ๋•Œ main ๋ฉ”์„œ๋“œ(ํ”„๋กœ์ ํŠธ๋ช…Application.java ์— ์กด์žฌ)๊ฐ€ ์‹คํ–‰๋  ์ˆ˜ ์žˆ๋„๋ก ํ•˜๋Š” ์„ค์ • ํŒŒ์ผ