본문 바로가기

IT

[Spring 강좌]Spring Boot 에서 단독 실행 가능한 War 배포 하기

반응형

1. Aplication을 수정합니다.

@SpringBootApplication
@MapperScan(basePackages = "com.portal.admin.main.dao")
@EnableAsync
public class PortalApplication extends SpringBootServletInitializer implements WebApplicationInitializer {
 
    public static void main(String[] args) {
        SpringApplication.run(PortalApplication.class, args);
    }
 
//추가
    @Override
  protected WebApplicationContext run(SpringApplication application) {
 
      return super.run(application);
  }
 
//추가
  @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(PortalApplication.class);
    }

 

 

2. pom.xml 에서 packaging war로 수정합니다.

... 생략 ...
 
 
  <!-- [수정]war로 수정한다. -->
  <packaging>war</packaging>
  <name>PORTAL_ADMIN</name>
  <description>Demo project for Spring Boot</description>
 
  <properties>
    <java.version>1.8</java.version>
  </properties>
 
  <dependencies>
    <!-- [추가]추가 한다 -->
    <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-tomcat</artifactId> 
      <scope>provided</scope> 
    </dependency>
 
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
 
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
      <scope>test</scope>
    </dependency>
     
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-jasper</artifactId>
    </dependency>
    <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-devtools</artifactId>
          <optional>true</optional>
      </dependency>
      
 
 
              .. . 생략 ...
 
 
 
  </dependencies>
 
 
    <build>
        <!-- portal_admin.war 가 생성된다. -->
          <finalName>portal_admin</finalName>
  <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
      </plugin>
    </plugins>
    </build>
 
 
</project>

 

3. Run As 에서 Maven Build... 선택 후 Goals 안에 clean package 라고 입력 후 Run 버튼을 누르면 war 파일이 생성됩니다.

 

 

4. 서버 콘솔에서 실행합니다.

$ java -jar portal_admin.war
반응형