LoginSignup
8
8

More than 5 years have passed since last update.

posh-gvmでWindowsにSpringBootをインストールして試してみたら楽ちんすぎて #yokohamagroovy

Last updated at Posted at 2014-06-01

posh-gvm https://github.com/flofreud/posh-gvm

まずはposh-gvmからSpringBootをインストール。

> gvm install springboot

Downloading: springboot 1.0.2.RELEASE

Downloaded 8135K of 8135K
Installing: springboot 1.0.2.RELEASE
Done installing!
Do you want springboot 1.0.2.RELEASE to be set as default? (Y/n): Y
Setting springboot 1.0.2.RELEASE as default.
>

SpringBootで使うコマンドは spring です。バージョンの確認をしてみる。

> spring --version

Spring CLI v1.0.2.RELEASE

spring-boot http://projects.spring.io/spring-boot/

リファレンスはここePub版pdf版も用意されてるようですよ!

まずはこんなスクリプトを用意してみましょう。

MyHelloWorldApp.groovy
@RestController
class MyHelloWorldApp {

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

}

そんで、こんなコマンドを打ってみましょう。

> spring run MyHelloWorldApp.groovy

Resolving dependencies.........................

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.0.2.RELEASE)

2014-06-01 16:27:28.478  INFO 10496 --- [       runner-0] o.s.boot.SpringApplication               : Starting applicatio
n on PC with PID 10496 (\.m2\repository\org\springframework\boot\spring-boot\1.0.2.RELEASE\spring-boot
-1.0.2.RELEASE.jar started by USER in \workspace)
(中略)
2014-06-01 16:27:32.229  INFO 10496 --- [       runner-0] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on p
ort(s): 8080/http
2014-06-01 16:27:32.232  INFO 10496 --- [       runner-0] o.s.boot.SpringApplication               : Started application
 in 4.136 seconds (JVM running for 6.931)

ほほう。では http://localhost:8080/ にアクセスしてみましょう。

hello-springboot.png

えっ…
ア工エエェェ(´д`)ェェエエ工ッ!?

マジでっ!!? これはびっくりするほど楽ちん!!
背後ではMavenによる依存性解決からTomcat Embeddedによるサーブレットコンテナの始動まで動いてますね。@RestControllerアノテーションを検出して暗黙にSpring MVC+Tomcat Embeddedの依存性を解決するようです。
もう軽量なWebアプリちょこっと書くならSpringBootでいいじゃん!

終了はCtrl+Cで。プロンプトに戻ります。

バッチ ジョブを終了しますか (Y/N)? Y
>

なお、リファレンスにSpring Boot does not require any specific code layout to workとあるように、特定のプロジェクト構造を要求するフレームワークではありませんが、GradleとMavenでのビルドに対応しているので、ソースコードが複数になるなら構造化してあげましょうね。

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