6
6

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 Boot/Groovy/Eclipseで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
Groovy-Eclipse plugin Version: 2.9.2.xx-201502282108-e43j8

前提条件

下の状態をJavaからGroovyに書き換えます

Spring IO,Spring Boot, Eclipse Gradle ProjectでHello world
http://qiita.com/quwahara/items/1bb7dcf8fd8100cc4ed9

Groovyをbuild.gradleに設定する

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

Eclipse/Gradle Java Projectで、後からGroovyもCompileできるようにする
http://qiita.com/quwahara/items/22a898b61d64dd1ee934

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

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'io.spring.dependency-management'
// Add
apply plugin: 'groovy'
// Add
sourceSets {
    main {
        java {
            srcDirs = []
        }
        groovy {
            srcDirs = ['src/main/java']
        }
    }
    test {
        java {
            srcDirs = []
        }
        groovy {
            srcDirs = ['src/test/java']
        }
    }
}

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

repositories {
    mavenCentral()
}

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

dependencies {
    // Add
    compile 'org.codehaus.groovy:groovy-all'
    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が追加される

javaをgoovyに変更

hello/SampleController.javaをhello/SampleController.groovyに名前変更

アプリケーションを実行

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

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

参考

次の記事

Groovyを使ったSpring Boot, Data JPA, MySQL操作の簡単な実装
http://qiita.com/quwahara/items/6567fd54772a879a7a6f

6
6
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
6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?