본문 바로가기

⭐ SpringBoot/개념

Springboot에 Undertow 적용하기

최초 프로젝트 생성 시

최초 프로젝트 생성 시 spring-boot의 내장 tomcat을 사용하는 것이 아닌 jboss의 undertow를 사용하는 방법은 아래와 같다.

일단 최초 프로젝트 생성 시 gradle.build에서 undertow 라이브러리만 추가해 주면 설치 및 실행이 된다.

일단 InteliJ의 커뮤니터 버전 기준으로 하면, Springboot 이니셜라이져에서 설정과 라이브러리를 다운받는다.

https://start.spring.io/

하지만 디펜던시 검색에서 undertow라는 라이브러리 검색이 안된다.

그래서 새로운 프로젝트를 생성 후 수동으로 undertow라이브러리를 추가해 주면 된다.

build.gradle 파일에서 아래와 같이 undertow를 디펜던시에 추가해 주면 된다.

dependencies {
	//tomcat 종속성 해제
	implementation ('org.springframework.boot:spring-boot-starter-web') {
		exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
	}
	//junit 관련 설정
	testImplementation('org.springframework.boot:spring-boot-starter-test') {
		exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
	}
	//undertow 추가
	implementation 'org.springframework.boot:spring-boot-starter-undertow'
	//나머지 라이브러리 추가
	implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
	implementation 'org.springframework.boot:spring-boot-starter-mustache'
	runtimeOnly 'com.h2database:h2'
	testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

추가 후 서버를 기동하면 기존 tomcat이 아닌 undertow가 실행되는것을 확인 할 수 있다.

실행 결과확인

localhost:8080 으로 접속하면 아래와 같이 웹 서버가 동작 하는것을 알 수 있다.