์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
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 | 29 | 30 |
- ๋ฆฟ์ฝ๋
- ํฉ๊ฒฉํ๊ธฐ
- charAt
- charAtCodeAt
- ์ฝ๋ฉํ ์คํธ
- clone coding
- javascript
- ์ฝํ
- Gradle
- f-lab
- ๋ฌธ์ ํ์ด
- sortedby
- sortby
- ํ๋ก๊ทธ๋๋จธ์ค
- SQLD
- SQLD๊ณต๋ถ๋ฒ
- serializable
- Spring Boot
- kotlin
- ๋ฌธ์์ด ์๋ฅด๊ธฐ
- SQL๊ฐ๋ฐ์
- 2์ฃผ์์ ์ฌ
- ๋ฌธ์์ด ์ฒ๋ฆฌ
- ๋ค์นด๋ผ์ฟ ๋ฐฐ๋นํ
- ์ฝ๋ฉํ ์คํธ์ ๋ฌธ
- ์ ํจ์ฑ๊ฒ์ฌ
- slice
- ํด๋ก ์ฝ๋ฉ
- SpringBootServletInitializer
- JPA
- Today
- Total
yoonix
[Spring Boot] SpringBootServletInitializer๋ ์ธ์ , ์ ํ์ํ๊ฐ? (WAR ๋ฐฐํฌ์ web.xml์ ์ฐจ์ด) ๋ณธ๋ฌธ
[Spring Boot] SpringBootServletInitializer๋ ์ธ์ , ์ ํ์ํ๊ฐ? (WAR ๋ฐฐํฌ์ web.xml์ ์ฐจ์ด)
yoonix 2025. 5. 21. 23:22๐งฉ ๊ฐ์
Spring Boot๋ฅผ ๊ณต๋ถํ๋ฉด์ SpringBootServletInitializer๋ผ๋ ํด๋์ค๋ฅผ ์ ํ๊ฒ ๋๋ค.
๋๋ ์ ์์ ๋ถํ๋ ์์ํฌ ํ๋ก์ ํธ๋ฅผ ํ ๋ web.xml์ ์ค์ ํ๊ณ ํฐ์บฃ์ WAR์ ๋ฐฐํฌํ๋ ๊ตฌ์กฐ์ ์ต์ํ๋ค.
๊ทธ๋์ Spring Boot์์๋ web.xml์ด ์๋ค๋ ๊ฒ ์์ํ๊ณ ,
๋์ฒด ์ด ๊ตฌ์กฐ์์ “๋ฉ์ธ ๋ฉ์๋ ์ญํ ”์ ๋๊ฐ ํด์ฃผ๋์ง,
WAR ๋ฐฐํฌ ์์๋ ์ด๋ค ์ค์ ์ด ํ์ํ์ง ๊ฐ๋
์ด ๋ค์ ๋ชจํธํ๊ฒ ๋๊ปด์ก๋ค.
์ด ๊ธ์ ๊ทธ๋ฐ ๊ถ๊ธ์ฆ์ ์ ๋ฆฌํ ์ผ์ข
์ ํ๊ณ ์ด์,
SpringBootServletInitializer์ ํ์์ฑ๊ณผ ์๋ ๋ฐฉ์์ JAR vs WAR ๋ฐฐํฌ ๊ตฌ์กฐ ์ฐจ์ด ์ค์ฌ์ผ๋ก ์ ๋ฆฌํ ๊ฒ์ด๋ค.
โ Spring Boot๋ ์ web.xml์ด ์์๊น?
์ ์์ ๋ถํ๋ ์์ํฌ(MVC2 ๊ธฐ๋ฐ)์์๋ ํฐ์บฃ ๊ฐ์ WAS์ .war ํ์ผ์ ๋ฐฐํฌํ๊ณ
๊ทธ ์์ web.xml์์ ๋ค์๊ณผ ๊ฐ์ ๊ฑธ ์ง์ ํ๋ค.
- ์์ ์๋ธ๋ฆฟ (DispatcherServlet ๋ฑ)
- ์ด๊ธฐ ํ๋ผ๋ฏธํฐ
- ์ธ๋ฑ์ค ํ์ผ (index.jsp ๋ฑ)
<web-app>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
</web-app>
๐ก Spring Boot๋ ๋ด์ฅ ํฐ์บฃ์ ํฌํจํ๊ณ ์์ด์, ์๋ฒ ์ค์ ์์ฒด๋ฅผ ์ฝ๋๋ก ์ฒ๋ฆฌํ๊ณ main() ํจ์๊ฐ ์ ํ๋ฆฌ์ผ์ด์ ์ ์์์ ์ญํ ์ ํ๊ธฐ ๋๋ฌธ.
์ฆ, ํฐ์บฃ๋, ์๋ธ๋ฆฟ ๋ฑ๋ก๋ ๋ค ์๋์ด๋ค.
โ ๊ทธ๋ฐ๋ฐ ์ธ๋ถ WAS์ WAR์ ๋ฐฐํฌํ ๋๋?
๋ฌธ์ ๋ Spring Boot๋ฅผ WAR๋ก ํจํค์งํด์ ์ธ๋ถ ํฐ์บฃ์ ๋ฐฐํฌํ ๊ฒฝ์ฐ๋ค.
์ด๋๋ ๋ ์ด์ main()์ ์ง์ ์คํํ ์ ์๋ค.
์ธ๋ถ ํฐ์บฃ์ web.xml ๋๋ Servlet API๋ฅผ ํตํด ์ด๋ค ํด๋์ค๊ฐ ์ ํ๋ฆฌ์ผ์ด์
์ ์์ํ ์ง ์์์ผ ํ๋ค.
๊ทธ๋์ ์ด๋ ํ์ํ ๊ฒ์ด ๋ฐ๋ก ๐ SpringBootServletInitializer
โ SpringBootServletInitializer๋?
์ธ๋ถ ํฐ์บฃ์ด Spring Boot ์ ํ๋ฆฌ์ผ์ด์
์ ๋ถํ
ํ ์ ์๋๋ก
์ง์
์ ์ ์ฐ๊ฒฐํด์ฃผ๋ ๋ธ๋ฆฟ์ง ํด๋์ค
๋ด์ฅ ํฐ์บฃ์ด ์๋ WAR ํ๊ฒฝ์์๋
์ธ๋ถ ํฐ์บฃ์ด web.xml์ Servlet์ ์ฐธ๊ณ ํด ์ง์
์ ์ ์ฐพ๋ฏ์ด,
Spring Boot์์๋ SpringBootServletInitializer๊ฐ ์ง์
์ ์ญํ ์ ํ๊ฒ ๋๋ค.
@SpringBootApplication
class MyApplication : SpringBootServletInitializer() {
override fun configure(application: SpringApplicationBuilder): SpringApplicationBuilder {
return application.sources(MyApplication::class.java)
}
}
โ ์ธ์ ํ์ํ๊ณ , ์ธ์ ํ์ ์๋๊ฐ?
๋ฐฐํฌ ๋ฐฉ์ | ํฐ์บฃ ์ข ๋ฅ | ํ์ ์ฌ๋ถ | ์ค๋ช |
java -jar | ๋ด์ฅ ํฐ์บฃ | โ ํ์ ์์ | main()์ด ์ง์ ์คํ๋จ |
.war ํ์ผ | ์ธ๋ถ ํฐ์บฃ | โ ํ์ํจ | WAS๊ฐ Spring์ ์ธ์ํ ์ ์๋๋ก ์ด๊ธฐํ ํด๋์ค ํ์ |
โ ๋ด์ฅ ํฐ์บฃ vs ์ธ๋ถ ํฐ์บฃ, ๋ญ๊ฐ ๋ค๋ฅธ๊ฐ?
ํญ๋ชฉ | ๋ด์ฅ ํฐ์บฃ | ์ธ๋ถ ํฐ์บฃ |
๋ฐฐํฌ | jar ์คํ | war ๋ณต์ฌ |
์ค์ ์์น | main() ๋ด๋ถ ์ค์ | server.xml, webapps ํด๋ ๋ฑ |
Spring ์คํ ๋ฐฉ์ | ์ง์ ์คํ | WAS๊ฐ ์คํ, Spring์ ๋ถ๋ฆ๋ฐ๋ ๊ตฌ์กฐ |
SpringBootServletInitializer ํ์ ์ฌ๋ถ | โ | โ |
โ ๊ทธ๋ผ jar๋ก ๋ง๋ค๋ฉด ๋ฌด์กฐ๊ฑด ๋ด์ฅ ํฐ์บฃ์ด ํฌํจ๋๋?
๋๋ถ๋ถ์ ๊ฒฝ์ฐ, YES.
- Spring Boot์์ spring-boot-starter-web๋ง ์์กดํ๋ฉด ์๋์ผ๋ก ๋ด์ฅ ํฐ์บฃ์ด ํฌํจ๋จ
- ๋ค๋ง, providedRuntime("...tomcat...")์ผ๋ก ์ค์ ํ๊ฑฐ๋
- Jetty/Nett ์๋ฒ๋ก ๊ต์ฒดํ๋ฉด ํฐ์บฃ์ ๋น ์ง
dependencies {
implementation("org.springframework.boot:spring-boot-starter-web") // ํฐ์บฃ ํฌํจ
// or
// providedRuntime("org.springframework.boot:spring-boot-starter-tomcat") // WAR์ฉ
}
+ โ๏ธ Gradle ์ค์ ์ ์ฃผ์์
WAR ๋น๋๋ฅผ ํ๋ ค๋ฉด build.gradle.kts์์ ๋ค์์ฒ๋ผ ์ค์ ํด์ผ ํ๋ค:
plugins {
id("war")
}
dependencies {
providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
}
providedRuntime ์ค์ ์ ํด์ค์ผ ๋ด์ฅ ํฐ์บฃ์ JAR์ ํฌํจ์ํค์ง ์๊ฒ ๋๋ค.
WAR๋ ํฐ์บฃ์ด ์ธ๋ถ์ ๋ฐ๋ก ์กด์ฌํ๋ฏ๋ก, ๋ด์ฅ ํฐ์บฃ์ ๋นผ์ค์ผ ํ๋ค.