在Windows上使用posh-gvm安装并试用Spring Boot,发现太容易了,真是太爽了!#yokohamagroovy

华丽的 GVM,可在 GitHub 上找到: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

春季启动:http://projects.spring.io/spring-boot/

这里有参考资料。似乎还提供了ePub版和pdf版本!

首先,让我们准备一个类似的脚本吧。

@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启动Servlet容器都在运行。它似乎能检测到@RestController注解并自动解决Spring MVC+Tomcat Embedded的依赖关系。
如果只是想快速编写轻量级Web应用,那就用SpringBoot吧!

使用Ctrl+C来结束。将回到提示符。

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

另外,正如在参考资料中提到的那样,“Spring Boot不需要任何特定的代码布局来工作”,它并不要求特定的项目结构,但它支持使用Gradle和Maven进行构建,因此如果源代码变得复杂,请进行结构化处理。

广告
将在 10 秒后关闭
bannerAds