5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Spring IO,Spring Boot, Eclipse Gradle ProjectでHello world

Last updated at Posted at 2015-06-07

環境

OS X Yosemite 10.10.3
jdk1.8.0_45.jdk

Spring Tool Suite

Version: 3.6.4.RELEASE
Build Id: 201503100337
Platform: Eclipse Kepler SR2 (4.3.2)

Gradle IDE plugin Version: 3.6.4.201503050952-RELEASE

前提条件

Eclipseが下の状態にあること

EclipseでGradle Java Porjectを新規作成する
http://qiita.com/quwahara/items/1bb7dcf8fd8100cc4ed9

Spring IOをbuild.gradleに設定する

下を参考に前提条件のbuild.gradleに// Addを追記

Spring IO Platform Reference Guide
4.2 Using Spring IO Platform with Gradle
http://docs.spring.io/platform/docs/1.1.2.RELEASE/reference/htmlsingle/#getting-started-using-spring-io-platform-gradle

build.gradle
// Add
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'io.spring.gradle:dependency-management-plugin:0.4.1.RELEASE'
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
// Add
apply plugin: 'io.spring.dependency-management'

sourceCompatibility = 1.5
version = '1.0'
jar {
    manifest {
        attributes 'Implementation-Title': 'Gradle Quickstart',
                   'Implementation-Version': version
    }
}

repositories {
    mavenCentral()
}

// Add
dependencyManagement {
    imports {
        mavenBom 'io.spring.platform:platform-bom:1.1.2.RELEASE'
    }
}

dependencies {
    // Add
    compile 'org.springframework.boot:spring-boot-starter-web'

    compile group: 'commons-collections', name: 'commons-collections', version: '3.2'
    testCompile group: 'junit', name: 'junit', version: '4.+'
}

test {
    systemProperties 'property': 'value'
}

uploadArchives {
    repositories {
       flatDir {
           dirs 'repos'
       }
    }
}

依存関係を更新

追記分を反映させるため依存関係を更新する
Package ExplorerでProjectのRoot要素を選択、右クリック
Gradle → Refresh All
Gradle Dependencies下に依存するLibraryが追加される

アプリケーション作成

下を参考にhello/SampleController.javaを作成

Spring Boot
Quick Start
http://projects.spring.io/spring-boot/#quick-start

hello/SampleController.java
package hello;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@EnableAutoConfiguration
public class SampleController {

    @RequestMapping("/")
    @ResponseBody
    String home() {
        return "Hello World!";
    }

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

アプリケーションを実行

Package Explorerでhello/SampleController.javaを選択、右クリック
Debug As → Spring Boot App

ブラウザで下のURLを開く
http://localhost:8080/

参考

次の記事

Spring Boot/Groovy/EclipseでHello world
http://qiita.com/quwahara/items/f4b1d30855fff83da3b8

5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?