2
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 + Kotlin + Gradleクイックスタート

Posted at

Spring + Kotlin + GradleでサクッとWebサーバーを起動する方法。

1. Spring Initializrで雛形を入手

上記サイトで

  • ProjectGradleに設定
  • LangulageKotlinに設定
  • Spring Boot2.1.4に設定

Generate Projectをクリックして、雛形をダウンロード。

スクリーンショット 2019-04-20 19.51.19.png

2. IDEAで簡単なプログラムを書く

ダウンロードした雛形(zipファイル)を解凍して、IDEAで開く。
次に、HelloControllerというファイル名で、以下のプログラム書いて、保存。

package com.example.demo

import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController

@RestController
class HelloController {

    @GetMapping("hello")
    fun hello(@RequestParam("name") name: String): String = "Hello, $name!"
}

org.springframework.webが見つからない場合:
build.gradledependenciesに以下の内容を追加。

	// https://mvnrepository.com/artifact/org.springframework/spring-web
	compile group: 'org.springframework', name: 'spring-web', version: '5.1.2.RELEASE'

3. プログラム実行

DemoApplication.ktのmain関数の隣の三角のマークをクリックして、実行する。
スクリーンショット 2019-04-20 20.00.30.png

実行したら、http://localhost:8080/hello?name=Spring にアクセス。結果↓
スクリーンショット 2019-04-20 20.12.29.png

実行した時に、即行でexitされる場合:
build.gradledependenciesに以下の内容を追加。参考リンク

compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '2.1.2.RELEASE'
2
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
2
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?