SpringBoot

[SpringBoot] war 추출

Xmobile 2020. 11. 17. 10:07

1. 배포시에 war를 톰켓에 올리기 위하여 war를 export하기 위해서  

하기 가이드를 참고하여 적용해 보도록 하겠습니다

https://docs.spring.io/spring-boot/docs/current/reference/html/howto.html#howto-traditional-deployment

 

“How-to” Guides

Spring Boot has no mandatory logging dependency, except for the Commons Logging API, which is typically provided by Spring Framework’s spring-jcl module. To use Logback, you need to include it and spring-jcl on the classpath. The recommended way to do th

docs.spring.io

 

1. SpringBootApplication에 SpringBootServletInitializer 상속 

@SpringBootApplication
public class DemoApplication extends SpringBootServletInitializer{ 

	public static void main(String[] args) {
		SpringApplication.run(DemoApplication.class, args);
	}
	
	@Override protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { 
		return builder.sources(DemoApplication.class); 
	}
}

 

2. build.gradle 설정 

1. id 'war' 추가 

plugins {
	id 'org.springframework.boot' version '2.3.2.RELEASE'
	id 'io.spring.dependency-management' version '1.0.9.RELEASE'
	id 'java'
	id "com.ewerk.gradle.plugins.querydsl" version "1.0.10"
	id 'war'
}

 

2. bootwar 적용

docs.spring.io/spring-boot/docs/current/gradle-plugin/api/org/springframework/boot/gradle/tasks/bundling/BootWar.html

bootWar {
	archiveBaseName = 'demoproject'
 	archiveVersion="0.0.1-SNAPSHOT"
}

3. dependencies 추가 

dependencies {
	...
	providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat' 
    ...
}

 

3. 확인

1. gradle bootWar실행 

2. war 확인 libs폴더 하위에 생성

위와 같이 war를 제대로 추출되는것을 확인 하였습니다.