Spring Boot CLI 提供Spring Spring 的引导命令行功能 云。你可以编写Groovy脚本来运行Spring Cloud组件 应用(例如)。您也可以轻松做到 诸如加密和解密以支持Spring Cloud Config之类的事情 具有机密配置值的客户端。使用启动器 CLI 您可以 可以启动Eureka,Zipkin,Config Server等服务 从命令行一次方便地全部使用(在 开发时间)。@EnableEurekaServer
Spring Cloud 是在非限制性 Apache 2.0 许可证下发布的。如果您想为文档的这一部分做出贡献,或者如果您发现错误,请在github 的项目中找到源代码和问题跟踪器。 |
安装
要安装,请使 确保您有Spring Boot CLI(2.0.0 或更高版本):
$ spring version
Spring CLI v2.2.3.RELEASE
例如,对于开发工具包用户
$ sdk install springboot 2.2.3.RELEASE
$ sdk use springboot 2.2.3.RELEASE
并安装弹簧云插件
$ mvn install
$ spring install org.springframework.cloud:spring-cloud-cli:2.2.0.RELEASE
先决条件:使用加密和解密功能 您需要在 JVM 中安装全功能型 JCE(默认情况下不存在)。 您可以下载“Java 加密扩展 (JCE) 无限强度管辖权策略文件” 从 Oracle 中,并按照说明进行安装(实质上替换了 2 个策略文件 在 JRE 库/安全目录中,其中包含您下载的那些)。 |
在开发中运行 Spring 云服务
启动器CLI 可用于运行常见的服务,如 尤里卡, 从命令行配置服务器等。列出可用的 您可以执行的服务,并启动默认设置 的服务只是。要选择要部署的服务, 只需在命令行上列出它们,例如spring cloud --list
spring cloud
$ spring cloud eureka configserver h2 kafka stubrunner zipkin
支持的可部署内容摘要:
服务 | 名字 | 地址 | 描述 |
尤里卡 | 尤里卡服务器 | http://localhost:8761 | 用于服务注册和发现的尤里卡服务器。默认情况下,所有其他服务都显示在其目录中。 |
配置服务器 | 配置服务器 | http://localhost:8888 | Spring Cloud Config Server 在“本机”配置文件中运行,并从本地目录 ./launcher 提供配置 |
H2 | H2 数据库 | http://localhost:9095(console), jdbc:h2:tcp://localhost:9096/{data} | 关系数据库服务。使用文件路径(例如)连接时。请记住,您可以添加与其他服务器类型兼容的连接。 |
卡 夫 卡 | 卡夫卡经纪人 | http://localhost:9091(执行器端点),本地主机:9092 | |
数据流 | 数据流服务器 | http://localhost:9393 | Spring Cloud Dataflow server,UI 位于 /admin-ui。将数据流外壳连接到根路径的目标。 |
齐普金 | 齐普金服务器 | http://localhost:9411 | 带有用于可视化跟踪的 UI 的 Zipkin 服务器。将跨度数据存储在内存中,并通过 JSON 数据的 HTTP POST 接受它们。 |
顽固的运行者 | 存根转轮引导 | http://localhost:8750 | 下载 WireMock 存根,启动 WireMock 并使用存储的存根为启动的服务器提供信息。传递以传递存根坐标,然后转到。 |
这些应用中的每一个都可以使用具有相同名称的本地 YAML 文件进行配置(在当前 工作目录或名为“config”或in的子目录)。例如,您可能想要 执行以下操作来查找后端的本地 Git 存储库:~/.spring-cloud
configserver.yml
configserver.yml
spring:
profiles:
active: git
cloud:
config:
server:
git:
uri: file://${user.home}/dev/demo/config-repo
例如,在存根运行器应用程序中,您可以通过以下方式从本地获取存根。.m2
stubrunner.yml
stubrunner:
workOffline: true
ids:
- com.example:beer-api-producer:+:9876
添加其他应用程序
可以添加其他应用程序(不是因为这会替换默认值),例如./config/cloud.yml
./config.yml
config/cloud.yml
spring:
cloud:
launcher:
deployables:
source:
coordinates: maven://com.example:source:0.0.1-SNAPSHOT
port: 7000
sink:
coordinates: maven://com.example:sink:0.0.1-SNAPSHOT
port: 7001
列出应用时:
$ spring cloud --list
source sink configserver dataflow eureka h2 kafka stubrunner zipkin
(请注意列表开头的其他应用)。
编写时髦的脚本和运行应用程序
Spring Cloud CLI 支持大多数 Spring Cloud 声明式 功能,例如批注类。例如 这是一个功能齐全的尤里卡服务器@Enable*
app.groovy
@EnableEurekaServer
class Eureka {}
你可以像这样从命令行运行
$ spring run app.groovy
要包含其他依赖项,通常只需添加 适当的功能启用注释,例如,或。手动包含 你可以使用与特殊的“弹簧启动”短的依赖关系 样式工件坐标,即仅使用工件 ID(无需 对于组或版本信息),例如,将客户端应用程序设置为 在AMQP上收听Spring CLoud Bus的管理事件:@EnableConfigServer
@EnableOAuth2Sso
@EnableEurekaClient
@Grab
app.groovy
@Grab('spring-cloud-starter-bus-amqp')
@RestController
class Service {
@RequestMapping('/')
def home() { [message: 'Hello'] }
}
加密和解密
Spring Cloud CLI 带有“加密”和“解密” 命令。两者都接受指定键的相同形式的参数 作为强制性的“--key”,例如
$ spring encrypt mysecret --key foo
682bc583f4641835fa2db009355293665d2647dade3375c0ee201de2a49f7bda
$ spring decrypt --key foo 682bc583f4641835fa2db009355293665d2647dade3375c0ee201de2a49f7bda
mysecret
在文件中使用密钥(例如,用于加密的 RSA 公钥)前置 带有“@”的键值并提供文件路径,例如
$ spring encrypt mysecret --key @${HOME}/.ssh/id_rsa.pub
AQAjPgt3eFZQXwt8tsHAVv/QHiY5sI2dRcR+...