玩玩 SpringBoot CLI

其实就是对这个工具感到好奇,然后记录一下。

先安装一下,下面的地址给出了好几种安装方式:

https://docs.spring.io/spring-boot/docs/current/reference/html/getting-started-installing-spring-boot.html#getting-started-installing-the-cli

因为我使用的mac,所以使用homevrew管理,执行以下的就可以啦,上面介绍了很多安装方式,我只是挑舒服的方式来。

当你安装好以后,就可以使用 spring 命令:

我们来看看安装的是什么版本:

使用 help 可以看没个命令的使用详情:

扫描二维码关注公众号,回复: 181614 查看本文章

让我们来写点 Groovy 程序来运行一下,因为springBoot cli已经自带了,所以不需要安装额外的 Groovy:

运行输出,是不是很熟悉:

启动以后,我们可以发现默认占用了 8080 端口

我们也可以在不同的端口启动:

spring run hello.groovy -- --server.port=9000

我们也可以设置 JVM 参数:

JAVA_OPTS=-Xmx1024m spring run hello.groovy

为了减少 Groovy 代码的大小,有些 import 是自动导入的,比如我们可以直接使用 @Component, @RestController, 和 @RequestMapping。

而且 SpringApplication 会为我们默认生成 main 方法。

使用 init 方法允许我们创建一个start.spring.io项目

spring init --build maven --groupId com.redhat.examples  --version 1.0 --java-version 1.8 --dependencies web  --name hola-springboot hola-springboot 

我们编译一下 mvn clean install

运行 mvn spring-boot:run

猜你喜欢

转载自my.oschina.net/u/2277632/blog/1793338
CLI