프로그래밍/Back end

[Back end] Spring Boot jar에서 war로 변경

Reference M1 2020. 12. 30. 14:26

 

1. pom.xml 에서 packging을 war를 변경하고 tomcat을 provided로 설정한다.

<packaging>war</packaging>

<dependencies>
	<dependency>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-tomcat</artifactId>
		<scope>provided</scope>
	</dependency>
</dependencies>

 

2. SpringBootServletInitializer를 상속받아 코드에서 서블릿을 초기화하는 코드를 추가해야한다.

import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;

public class ServletInitializer extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(EduApplication.class);
    }

}

 

3. maven install 이나 build를 실행한다.