Spring Boot CLI——centos7
Spring Boot是一个命令行工具,用于使用Spring进行快速原型搭建。它允许你运行Groovy脚本,这意味着你可以使用类Java的语法,并且没有那么多的模板代码。
所有版本下载地址
这里下载的版本spring-boot-cli-2.2.0.BUILD-20190222.193142-143-bin.tar.gz
下载完成后解压
tar spring-boot-cli-2.2..BUILD-20190222.193142--bin.tar.gz -C /home/maxzhao/
cd /home/maxzhao
mv spring-2.2..BUILD-SNAPSHOT spring-2.2.-cli
cd spring-2.2.-cli
当前目录下有INSTALL.txt文件,这里面就是具体的安装方法。
INSTALL.txt文件中讲的很清楚了,spring-boot-cli-2.2.0 需要JDK1.8+
环境变量配置:
# 管理员下
# set springboot-cli
vim /etc/profile
#最后输入
export SPRING_HOME="/home/maxzhao/soft/spring-2.2.0-cli"
export PATH="$SPRING_HOME/bin:$PATH"
#保存
source /etc/profile
spring --version
# Spring CLI v2.2.0.BUILD-SNAPSHOT
简单的springboot-cli例子
运行Groovy脚本
在完成了Spring Boot CLI的安装之后,我们来试试使用它来快速的构建一个Spring Boot应用,方法很简单,只需要如下操作:
第一步:新建一个Groovy脚本,hello.groovy,内容如下:
@RestController
class ThisWillActuallyRun { @RequestMapping("/")
String home() {
"Hello World!"
} }
第二步:使用spring命令运行该Groovy脚本,具体如下:
$ spring run hello.groovy
Resolving dependencies............................................... *::::::::::::::*
::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::: :.
*::::::::::::::::::::::::::::::::::::: :*:
::::::::::::::::::::::::::::::::::::::::::: *:
.:::::::::::::::::::::::::::::::::::::::::: :
::::::::::::::::::::::::::::::::::::::::::. .:
::::::::::::::::::::::::::::::::::::::::: :
:::::::::::::::::::::::::::::::::::::: *:
:::::::::::::::::::::::::::::::::* :
:::::::::::::::::::* :
::::::::::::::: * *:
.:::::::::::: * .:
:::::::::::. : :
:::::::::: : .:
:::::::::: :: .:
.:::::::: ::: :*
:::::::: ::: :
:::::::: :::: ::
::::::: ::::: *:
::::::: *::::::: ::
:::::::. ::::::::::: :::
:::::::::::::::::::::::* ::::
.::: :::::::::* .:::::*
: ::::::::::::::::::::::::::::::::::::
. .:::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::
*::::::::::::::* -- ::20.571 INFO --- [ runner-] o.s.boot.SpringApplication : Starting application on zhaiyongchaodeMacBook-Pro.local with PID (started by zhaiyongchao in /Users/zhaiyongchao/Downloads)
-- ::20.574 INFO --- [ runner-] o.s.boot.SpringApplication : No active profile set, falling back to default profiles: default
-- ::20.732 INFO --- [ runner-] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@3c3ad454: startup date [Wed Apr :: CST ]; root of context hierarchy
-- ::21.758 INFO --- [ runner-] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): (http)
-- ::21.783 INFO --- [ runner-] o.apache.catalina.core.StandardService : Starting service [Tomcat]
-- ::21.784 INFO --- [ runner-] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.
-- ::21.795 INFO --- [ost-startStop-] o.a.catalina.core.AprLifecycleListener : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [/Users/zhaiyongchao/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.]
-- ::21.849 INFO --- [ost-startStop-] org.apache.catalina.loader.WebappLoader : Unknown loader org.springframework.boot.cli.compiler.ExtendedGroovyClassLoader$DefaultScopeParentClassLoader@5e3b901 class org.springframework.boot.cli.compiler.ExtendedGroovyClassLoader$DefaultScopeParentClassLoader
-- ::21.884 INFO --- [ost-startStop-] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
-- ::21.885 INFO --- [ost-startStop-] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in ms
-- ::22.042 INFO --- [ost-startStop-] o.s.b.w.servlet.ServletRegistrationBean : Servlet dispatcherServlet mapped to [/]
-- ::22.049 INFO --- [ost-startStop-] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-04-04 18:11:22.049 INFO 70477 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-04-04 18:11:22.049 INFO 70477 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2018-04-04 18:11:22.049 INFO 70477 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2018-04-04 18:11:22.391 INFO 70477 --- [ runner-0] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@3c3ad454: startup date [Wed Apr 04 18:11:20 CST 2018]; root of context hierarchy
2018-04-04 18:11:22.489 INFO 70477 --- [ runner-0] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/]}" onto public java.lang.String ThisWillActuallyRun.home()
2018-04-04 18:11:22.495 INFO 70477 --- [ runner-0] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2018-04-04 18:11:22.496 INFO 70477 --- [ runner-0] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2018-04-04 18:11:22.550 INFO 70477 --- [ runner-0] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-04-04 18:11:22.550 INFO 70477 --- [ runner-0] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-04-04 18:11:22.598 INFO 70477 --- [ runner-0] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
-- ::22.955 INFO --- [ runner-] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
-- ::23.004 INFO --- [ runner-] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): (http) with context path ''
-- ::23.010 INFO --- [ runner-] o.s.boot.SpringApplication
从日志中我们可以看到我们通过Groovy脚本定义的一个简单web应用就构建成功了,可以通过访问localhost:8080来验证一下上面应用提供的接口:
$ curl localhost:
Hello World!
可以在命令中附加spring配置参数,注意要多加一个--
$ spring run hello.groovy -- --server.port=
要设置JVM参数,可以使用JAVA_OPTS环境变量,比如:
$ JAVA_OPTS=-Xmx1024m spring run hello.groovy
初始化新项目
使用init命令可以创建一个新的项目。如:
$ spring init --dependencies=web,data-jpa my-project
这个命令会创建一个名为my-project的目录,在其中包含一个基于Maven的项目,并添加对于spring-boot-starter-web和spring-boot-starter-data-jpa的依赖。
你可以使用--list标记来显示所有可用的依赖。
$ spring init --list
运行spring help init可以查看具体的使用说明。
如下的命令会创建一个基于Gradle和java8的打包类型为war的项目。
$ spring init --build=gradle --java-version=1.8 --dependencies=websocket --packaging=war sample-app.zip
使用Spring Shell
Spring Boot CLI内置了一个shell,执行spring shell即可启动。这个shell支持ANSI彩色输出和tab键,如果要执行原生命令,在命令前加上!前缀即可。更多具体使用方法,可以在进入shell后输入help查看。
更多资料
可以在这里找到更多的groovy脚本例子,这里有Spring Build tool plugins相关的文档。
Spring Boot CLI——centos7的更多相关文章
- Spring Boot CLI安装
Spring Boot是一个命令行工具,用于使用Spring进行快速原型搭建.它允许你运行Groovy脚本,这意味着你可以使用类Java的语法,并且没有那么多的模板代码. 你没有必要为了使用Sprin ...
- 新手必看,Spring Boot CLI 必会必知
Spring Boot CLI 是什么 Spring Boot CLI 是 Spring Boot Commad Line 的缩写,是 Spring Boot 命令行工具.在 Spring Boot ...
- spring boot cli 知识点
spring boot cli 版本列表: https://repo.spring.io/snapshot/org/springframework/boot/spring-boot-cli/ spri ...
- OSX Homebrew 安装 Spring Boot CLI
OSX Homebrew 安装 Spring Boot CLI 如果您使用的是Mac并使用Homebrew,则可以使用以下命令安装Spring Boot CLI: $ brew tap pivotal ...
- Spring boot 官网学习笔记 - Spring Boot CLI 入门案例
安装CLI https://repo.spring.io/release/org/springframework/boot/spring-boot-cli/2.1.1.RELEASE/spring-b ...
- Spring Boot Cli下载安装
本地下载地址: spring-boot-cli-2.1.8.RELEASE-bin.zip : https://pan.baidu.com/s/1GMyxj1PecsM4BG_hzoteVQ spr ...
- spring-boot学习 (Groovy与Spring Boot Cli)
一.使用idea创建一个spring-boot项目,选择groovy语言 二.编写相应代码 1.创建实例类 package com.zhi.example class Man { Long id St ...
- 【微框架】之一:从零开始,轻松搞定SpringCloud微框架系列--开山篇(spring boot 小demo)
Spring顶级框架有众多,那么接下的篇幅,我将重点讲解SpringCloud微框架的实现 Spring 顶级项目,包含众多,我们重点学习一下,SpringCloud项目以及SpringBoot项目 ...
- Spring Boot
Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程.该框架使用了特定的方式来进行配置,从而使开发人员不再需要定义样板化的配置.通过 ...
随机推荐
- 国际化(i18n) 各国语言缩写
internationalization (国际化)简称:i18n,因为在i和n之间还有18个字符,localization(本地化 ),简称L10n. 一般用语言_地区的形式表示一种语言,如:zh_ ...
- [LeetCode] 0752. Open the Lock 打开转盘锁
题目 You have a lock in front of you with 4 circular wheels. Each wheel has 10 slots: '0', '1', '2', ' ...
- 序列:SEQUENCE
一.序列介绍 Oracle的序列是一种数据库对象,主要作用是用来产生唯一值.序列被创建以后可以通过数据字典找到序列对象,因此序列可以被多个对象共享. 二.创建序列 序列使用CREATE SEQUENC ...
- 导出到CSV文件
一.手工导出导出 1.winform void DataGridViewToExcel(DataGridView dataGridView1) { SaveFileDialog saveFileDia ...
- 容错(Fault-tolerance)
Spark Streaming的容错包括了三个地方的容错: 1.Executor失败容错:Executor的失败会重新启动一个新的Executor,这个是Spark自身的特性.如果Receiver所在 ...
- 关于devexpress报表XtraReport,动态修改报表样式(.repx格式),动态添加数据并使用的理解
一.基本概念: XtraReports 中的每个报表都由 XtraRepot 类的一个实例表示,或者由该类的子类来表示(这种情况更常见). 因此,每个报表都作为带区的容器使用,而每个带区中都包含报表控 ...
- Idea导入maven项目
1.idea中有项目的关闭项目 File>>close project 回到截图 下一步>下一步
- 01_搭建新浪云SAE
Step1:注册新浪云计算平台用新浪微博登陆新浪云计算平台,网址:http://sae.sina.com.cn/ 登陆成功之后会跳转到安全设置页面,安全设置页面要填写的东西比较多,需要注意:安全设置里 ...
- 六.搭建基本的Web服务
1.安装httpd软件包 ]# yum -y install httpd 2.重起httpd服务 ]# systemctl restart httpd ]# systemctl enable http ...
- JS发送验证码;并设置cookie
Tool.send_code = function(obj) { var isCheck = true, form = $('#editInfo_Form'); var mobile = form.f ...