Skip to content

Instantly share code, notes, and snippets.

@benelog
Last active August 29, 2015 14:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save benelog/d320305ec724384bb0c5 to your computer and use it in GitHub Desktop.
Save benelog/d320305ec724384bb0c5 to your computer and use it in GitHub Desktop.
spring-boot example
spring:
view:
prefix: /WEB-INF/view/
suffix: .jsp
server:
tomcat:
uri-encoding : UTF-8
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.1.2.RELEASE")
}
}
apply plugin: 'war'
apply plugin: 'spring-boot'
repositories {
mavenCentral()
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.springframework.boot:spring-boot-starter-actuator")
providedCompile("org.springframework.boot:spring-boot-starter-tomcat")
providedCompile("org.apache.tomcat.embed:tomcat-embed-jasper")
testCompile("org.springframework.boot:spring-boot-starter-test")
}

1. GVM 설치

curl -s get.gvmtool.net | bash

2. Gradle 설치

gvm install gradle

3. build.gradle 작성

mkdir boot
cd boot
vi build.gradle

파일내용

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:1.0.2.RELEASE")
    }
}

apply plugin: 'java'
apply plugin: 'spring-boot'

repositories {
    mavenCentral()
}

dependencies {
    compile("org.springframework.boot:spring-boot-starter-web")
}

4. Application.java 작성

mkdir src/main/java -p
vi src/main/java/Application.java

파일 내용

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@EnableAutoConfiguration
public class Application {
    @RequestMapping("/")
    String home() {
        return "Hello World!";
    }

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

5. Gradle로 서버 실행

gradle bootRun

6. 패키징

gradle bootRepackage

7. 패키징 파일 실행

cd build/libs
java -jar boot.jar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment