玩玩 SpringBoot CLI

其實就是對這個工具感到好奇,而後記錄一下。html

先安裝一下,下面的地址給出了好幾種安裝方式:java

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

由於我使用的mac,因此使用homevrew管理,執行如下的就能夠啦,上面介紹了不少安裝方式,我只是挑舒服的方式來。spring

當你安裝好之後,就能夠使用 spring 命令:springboot

咱們來看看安裝的是什麼版本:app

使用 help 能夠看沒個命令的使用詳情:maven

讓咱們來寫點 Groovy 程序來運行一下,由於springBoot cli已經自帶了,因此不須要安裝額外的 Groovy:spring-boot

運行輸出,是否是很熟悉:工具

啓動之後,咱們能夠發現默認佔用了 8080 端口ui

咱們也能夠在不一樣的端口啓動:

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

相關文章
相關標籤/搜索