티스토리 뷰

SpringBoot Web Application War 배포하기

SpringBoot Web Application 을 War 로 배포하는 방법을 소개하고자 한다. 특히 JBoss EAP 6, 7 에 배포하기 위해 시행착오가 많았다.

Java Application

  • SpringBoot 메인 Application 클래스에 SpringBootServletInitializer 클래스를 상속한다.
  • configure method 를 오버라이딩 한다.
  • Servlet 3.0 이상에서 지원한다. 이전 버젼에서는 web.xml 을 이용한 설정 방법을 사용해야 한다.
@SpringBootApplication
public class Application extends SpringBootServletInitializer {

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

    public static void main(String[] args) throws Exception {
        SpringApplication.run(Application.class, args);
    }

}

Configuration

  • Spring Boot 설정 파일이다. /api 를 context root 이름으로 지정했다.
  • Servlet Path 는 /* 로 지정해 줘야 한다. JBoss 6, 7 에서 default (/) 패스로 동작하지 않는다. (여기서 삽질)
  • application.properties
server.port=8080
server.servlet-path=/*
server.contextPath=/api
  • application.yaml
server:
  port: 8080
  servletPath: /*
  contextPath: /api

pom.xml

  • packaging 유형을 war 로 변경한다.
  • 임베디드 톰캣 라이브러리에 대한 dependency를 제거한다. 방법은 아래 2가지가 있다.
    • spring-boot-starter-web 에서 spring-boot-starter-tomcatexclusion 처리
    • spring-boot-starter-tomcatscopeprovided 로 설정
<dependencies>
    <!-- … -->
    <packaging>war</packaging>    
    <!-- … -->
    <dependency>
      <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <exclusions>
      <exclusion>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
      </exclusion>
    </exclusions>
  </dependency>
    <!-- … -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>
    <!-- … -->

</dependencies>

jboss-web.xml

JBoss EAP 에서 필요하다. Tomcat 은 해당사항 없음.

<jboss-web>
  <context-root>/api</context-root>
</jboss-web>
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/09   »
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
글 보관함