투케이2K

23. (spring/스프링) 스프링 gradle 환경 war 파일 생성 방법 본문

Spring

23. (spring/스프링) 스프링 gradle 환경 war 파일 생성 방법

투케이2K 2021. 8. 28. 07:37
반응형

[개발 환경 설정]

개발 툴 : inteli j

개발 언어 : spring


[폴더 및 파일 설정]


[소스 코드]

[소스코드 : build.gradle]

plugins {
    id 'org.springframework.boot' version '2.5.4'
    id 'io.spring.dependency-management' version '1.0.11.RELEASE'
    id 'java'

    // war file create
    id 'war'
}

group = 'com.project'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'


//configurations {
//    compileOnly {
//        extendsFrom annotationProcessor
//    }
//}


// war file create
configurations {
    developmentOnly
    runtimeClasspath {
        extendsFrom developmentOnly
    }
    compileOnly {
        extendsFrom annotationProcessor
    }
}


repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-jdbc'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:2.2.0'
    compileOnly 'org.projectlombok:lombok'
    developmentOnly 'org.springframework.boot:spring-boot-devtools'
    runtimeOnly 'com.oracle.database.jdbc:ojdbc8'
    annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
    annotationProcessor 'org.projectlombok:lombok'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'

    //thymeleaf use
    implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'

    //thymeleaf layout
    implementation('nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect')

    // war file create
    providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
    implementation 'javax.servlet:jstl'
}

test {
    useJUnitPlatform()
}










[소스코드 : ServletInitializer]

package com.project.researchpackage;

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

// war file create
public class ServletInitializer extends SpringBootServletInitializer {

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

}

 

반응형
Comments