(window.webpackJsonp=window.webpackJsonp||[]).push([[418],{850:function(t,e,r){"use strict";r.r(e);var a=r(56),n=Object(a.a)({},(function(){var t=this,e=t.$createElement,r=t._self._c||e;return r("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[r("h1",{attrs:{id:"spring-引导云-cli"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#spring-引导云-cli"}},[t._v("#")]),t._v(" Spring 引导云 CLI")]),t._v(" "),r("p",[t._v("Spring Boot CLI 为"),r("a",{attrs:{href:"https://projects.spring.io/spring-boot",target:"_blank",rel:"noopener noreferrer"}},[t._v("Spring Boot"),r("OutboundLink")],1),t._v("提供了"),r("a",{attrs:{href:"https://github.com/spring-cloud",target:"_blank",rel:"noopener noreferrer"}},[t._v("Spring Cloud"),r("OutboundLink")],1),t._v("命令行功能。你可以编写 Groovy 脚本来运行 Spring Cloud组件应用程序(例如"),r("code",[t._v("@EnableEurekaServer")]),t._v(")。你还可以轻松地进行加密和解密等操作,以支持具有秘密配置值的云配置客户机。通过 Launcher CLI,你可以方便地从命令行同时启动像 Eureka、Zipkin、Config Server 这样的服务(在开发时非常有用)。")]),t._v(" "),r("table",[r("thead",[r("tr",[r("th"),t._v(" "),r("th",[t._v("Spring Cloud是在非限制性的 Apache2.0 许可下发布的。如果你想对文档的这一部分做出贡献,或者你发现了一个错误,请在"),r("a",{attrs:{href:"https://github.com/spring-cloud/spring-cloud-cli",target:"_blank",rel:"noopener noreferrer"}},[t._v("github"),r("OutboundLink")],1),t._v("上找到项目中的源代码和问题追踪器。")])])]),t._v(" "),r("tbody")]),t._v(" "),r("h2",{attrs:{id:"安装"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#安装"}},[t._v("#")]),t._v(" "),r("a",{attrs:{href:"#_installation"}},[t._v("安装")])]),t._v(" "),r("p",[t._v("要安装,请确保你有"),r("a",{attrs:{href:"https://github.com/spring-projects/spring-boot",target:"_blank",rel:"noopener noreferrer"}},[t._v("Spring Boot CLI"),r("OutboundLink")],1),t._v("(2.0.0 或更好):")]),t._v(" "),r("div",{staticClass:"language- extra-class"},[r("pre",{pre:!0,attrs:{class:"language-text"}},[r("code",[t._v("$ spring version\nSpring CLI v2.2.3.RELEASE\n")])])]),r("p",[t._v("例如,对于 SDKMAN 个用户")]),t._v(" "),r("div",{staticClass:"language- extra-class"},[r("pre",{pre:!0,attrs:{class:"language-text"}},[r("code",[t._v("$ sdk install springboot 2.2.3.RELEASE\n$ sdk use springboot 2.2.3.RELEASE\n")])])]),r("p",[t._v("并安装 Spring Cloud插件")]),t._v(" "),r("div",{staticClass:"language- extra-class"},[r("pre",{pre:!0,attrs:{class:"language-text"}},[r("code",[t._v("$ mvn install\n$ spring install org.springframework.cloud:spring-cloud-cli:2.2.0.RELEASE\n")])])]),r("table",[r("thead",[r("tr",[r("th"),t._v(" "),r("th",[t._v("**先决条件:**要使用加密和解密功能"),r("br"),t._v(",你需要在你的 JVM 中安装全强度 JCE(默认情况下不存在)。"),r("br"),t._v("你可以从 Oracle 下载“Java Cryptography Extension(JCE)Unlimited Strength Juridictory Policy Files”"),r("br"),t._v(",并遵循安装说明(基本上将 JRElib/security 目录中的 2 个策略文件"),r("br"),t._v("替换为你下载的文件)。")])])]),t._v(" "),r("tbody")]),t._v(" "),r("h2",{attrs:{id:"running-spring-cloud-services-in-development"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#running-spring-cloud-services-in-development"}},[t._v("#")]),t._v(" "),r("a",{attrs:{href:"#_running_spring_cloud_services_in_development"}},[t._v("Running Spring Cloud Services in Development")])]),t._v(" "),r("p",[t._v("启动器 CLI 可用于从命令行运行公共服务,如 Eureka、Config Server 等。要列出你可以执行"),r("code",[t._v("spring cloud --list")]),t._v("的可用服务,并仅启动"),r("code",[t._v("spring cloud")]),t._v("的默认服务集。要选择要部署的服务,只需在命令行中列出它们,例如。")]),t._v(" "),r("div",{staticClass:"language- extra-class"},[r("pre",{pre:!0,attrs:{class:"language-text"}},[r("code",[t._v("$ spring cloud eureka configserver h2 kafka stubrunner zipkin\n")])])]),r("p",[t._v("支持的可部署程序摘要:")]),t._v(" "),r("table",[r("thead",[r("tr",[r("th",[t._v("Service")]),t._v(" "),r("th",[t._v("Name")]),t._v(" "),r("th",[t._v("Address")]),t._v(" "),r("th",[t._v("说明")])])]),t._v(" "),r("tbody",[r("tr",[r("td",[t._v("eureka")]),t._v(" "),r("td",[t._v("Eureka Server")]),t._v(" "),r("td",[r("a",{attrs:{href:"http://localhost:8761",target:"_blank",rel:"noopener noreferrer"}},[t._v("http://localhost:8761"),r("OutboundLink")],1)]),t._v(" "),r("td",[t._v("服务注册和发现的 Eureka 服务器。默认情况下,所有其他服务都会显示在其目录中。")])]),t._v(" "),r("tr",[r("td",[t._v("configserver")]),t._v(" "),r("td",[t._v("Config Server")]),t._v(" "),r("td",[r("a",{attrs:{href:"http://localhost:8888",target:"_blank",rel:"noopener noreferrer"}},[t._v("http://localhost:8888"),r("OutboundLink")],1)]),t._v(" "),r("td",[t._v("Spring 运行在“本机”配置文件中的云配置服务器和来自本地目录的服务配置。/Launcher")])]),t._v(" "),r("tr",[r("td",[t._v("h2")]),t._v(" "),r("td",[t._v("H2 Database")]),t._v(" "),r("td",[r("a",{attrs:{href:"http://localhost:9095",target:"_blank",rel:"noopener noreferrer"}},[t._v("http://localhost:9095"),r("OutboundLink")],1),t._v(" (console), jdbc:h2:tcp://localhost:9096/{data}")]),t._v(" "),r("td",[t._v("关系数据库服务。在连接时使用"),r("code",[t._v("{data}")]),t._v("的文件路径(例如"),r("code",[t._v("./target/test")]),t._v(")。请记住,你可以添加"),r("code",[t._v(";MODE=MYSQL")]),t._v("或"),r("code",[t._v(";MODE=POSTGRESQL")]),t._v("以与其他服务器类型的兼容性连接。")])]),t._v(" "),r("tr",[r("td",[t._v("kafka")]),t._v(" "),r("td",[t._v("Kafka Broker")]),t._v(" "),r("td",[r("a",{attrs:{href:"http://localhost:9091",target:"_blank",rel:"noopener noreferrer"}},[t._v("http://localhost:9091"),r("OutboundLink")],1),t._v(" (actuator endpoints), localhost:9092")]),t._v(" "),r("td")]),t._v(" "),r("tr",[r("td",[t._v("dataflow")]),t._v(" "),r("td",[t._v("Dataflow Server")]),t._v(" "),r("td",[r("a",{attrs:{href:"http://localhost:9393",target:"_blank",rel:"noopener noreferrer"}},[t._v("http://localhost:9393"),r("OutboundLink")],1)]),t._v(" "),r("td",[t._v("Spring 带有 ui at/admin-ui 的云数据流服务器。将 DataFlow Shell 连接到根路径上的目标。")])]),t._v(" "),r("tr",[r("td",[t._v("zipkin")]),t._v(" "),r("td",[t._v("Zipkin Server")]),t._v(" "),r("td",[r("a",{attrs:{href:"http://localhost:9411",target:"_blank",rel:"noopener noreferrer"}},[t._v("http://localhost:9411"),r("OutboundLink")],1)]),t._v(" "),r("td",[t._v("Zipkin 服务器与 UI 可视化的痕迹。存储在内存中的跨数据,并通过 JSON 数据的 HTTP POST 接受它们。")])]),t._v(" "),r("tr",[r("td",[t._v("stubrunner")]),t._v(" "),r("td",[t._v("Stub Runner Boot")]),t._v(" "),r("td",[r("a",{attrs:{href:"http://localhost:8750",target:"_blank",rel:"noopener noreferrer"}},[t._v("http://localhost:8750"),r("OutboundLink")],1)]),t._v(" "),r("td",[t._v("下载 WiRemock 存根,启动 WiRemock,并用存储的存根向启动的服务器提供信息。传递"),r("code",[t._v("stubrunner.ids")]),t._v("以传递存根坐标,然后转到"),r("code",[t._v("[http://localhost:8750/stubs](http://localhost:8750/stubs)")]),t._v("。")])])])]),t._v(" "),r("p",[t._v("这些应用程序中的每一个都可以使用同名的本地 YAML 文件进行配置(在当前工作目录或名为“config”的子目录中或在"),r("code",[t._v("~/.spring-cloud")]),t._v("中)。例如,在"),r("code",[t._v("configserver.yml")]),t._v("中,你可能想做这样的事情来为后端定位一个本地 Git 存储库:")]),t._v(" "),r("p",[t._v("configserver.yml")]),t._v(" "),r("div",{staticClass:"language- extra-class"},[r("pre",{pre:!0,attrs:{class:"language-text"}},[r("code",[t._v("spring:\n profiles:\n active: git\n cloud:\n config:\n server:\n git:\n uri: file://${user.home}/dev/demo/config-repo\n")])])]),r("p",[t._v("例如,在 Stub Runner 应用程序中,你可以通过以下方式从本地"),r("code",[t._v(".m2")]),t._v("获取 stub。")]),t._v(" "),r("p",[t._v("Stubrunner.yml")]),t._v(" "),r("div",{staticClass:"language- extra-class"},[r("pre",{pre:!0,attrs:{class:"language-text"}},[r("code",[t._v("stubrunner:\n workOffline: true\n ids:\n - com.example:beer-api-producer:+:9876\n")])])]),r("h3",{attrs:{id:"添加其他应用程序"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#添加其他应用程序"}},[t._v("#")]),t._v(" "),r("a",{attrs:{href:"#_adding_additional_applications"}},[t._v("添加其他应用程序")])]),t._v(" "),r("p",[t._v("可以将其他应用程序添加到"),r("code",[t._v("./config/cloud.yml")]),t._v("(而不是"),r("code",[t._v("./config.yml")]),t._v(",因为这将替换默认值),例如使用")]),t._v(" "),r("p",[t._v("config/cloud.yml")]),t._v(" "),r("div",{staticClass:"language- extra-class"},[r("pre",{pre:!0,attrs:{class:"language-text"}},[r("code",[t._v("spring:\n cloud:\n launcher:\n deployables:\n source:\n coordinates: maven://com.example:source:0.0.1-SNAPSHOT\n port: 7000\n sink:\n coordinates: maven://com.example:sink:0.0.1-SNAPSHOT\n port: 7001\n")])])]),r("p",[t._v("当你列出应用程序时:")]),t._v(" "),r("div",{staticClass:"language- extra-class"},[r("pre",{pre:!0,attrs:{class:"language-text"}},[r("code",[t._v("$ spring cloud --list\nsource sink configserver dataflow eureka h2 kafka stubrunner zipkin\n")])])]),r("p",[t._v("(请注意列表开头的附加应用)。")]),t._v(" "),r("h2",{attrs:{id:"编写-groovy-脚本并运行应用程序"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#编写-groovy-脚本并运行应用程序"}},[t._v("#")]),t._v(" "),r("a",{attrs:{href:"#_writing_groovy_scripts_and_running_applications"}},[t._v("编写 Groovy 脚本并运行应用程序")])]),t._v(" "),r("p",[t._v("Spring Cloud CLI 具有对 Spring Cloud的大多数声明性功能的支持,例如"),r("code",[t._v("@Enable*")]),t._v("类的注释。例如,这里有一个功能齐全的 Eureka 服务器")]),t._v(" "),r("p",[t._v("App.Groovy")]),t._v(" "),r("div",{staticClass:"language- extra-class"},[r("pre",{pre:!0,attrs:{class:"language-text"}},[r("code",[t._v("@EnableEurekaServer\nclass Eureka {}\n")])])]),r("p",[t._v("你可以像这样从命令行运行它")]),t._v(" "),r("div",{staticClass:"language- extra-class"},[r("pre",{pre:!0,attrs:{class:"language-text"}},[r("code",[t._v("$ spring run app.groovy\n")])])]),r("p",[t._v("要包含额外的依赖关系,通常只需添加适当的支持特性的注释就足够了,例如"),r("code",[t._v("@EnableConfigServer")]),t._v(","),r("code",[t._v("@EnableOAuth2Sso")]),t._v("或"),r("code",[t._v("@EnableEurekaClient")]),t._v("。要手动包含依赖项,你可以使用"),r("code",[t._v("@Grab")]),t._v("和特殊的“ Spring 引导”短样式工件坐标,即只使用工件 ID(不需要组或版本信息),例如,设置一个客户端应用程序,以便在 AMQP 上监听来自 Spring Cloud总线的管理事件:")]),t._v(" "),r("p",[t._v("App.Groovy")]),t._v(" "),r("div",{staticClass:"language- extra-class"},[r("pre",{pre:!0,attrs:{class:"language-text"}},[r("code",[t._v("@Grab('spring-cloud-starter-bus-amqp')\n@RestController\nclass Service {\n @RequestMapping('/')\n def home() { [message: 'Hello'] }\n}\n")])])]),r("h2",{attrs:{id:"加密和解密"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#加密和解密"}},[t._v("#")]),t._v(" "),r("a",{attrs:{href:"#_encryption_and_decryption"}},[t._v("加密和解密")])]),t._v(" "),r("p",[t._v("Spring cloud cli 带有一个“加密”和一个“解密”命令。两者都接受相同形式的参数,其中一个键被指定为强制性的“--key”,例如。")]),t._v(" "),r("div",{staticClass:"language- extra-class"},[r("pre",{pre:!0,attrs:{class:"language-text"}},[r("code",[t._v("$ spring encrypt mysecret --key foo\n682bc583f4641835fa2db009355293665d2647dade3375c0ee201de2a49f7bda\n$ spring decrypt --key foo 682bc583f4641835fa2db009355293665d2647dade3375c0ee201de2a49f7bda\nmysecret\n")])])]),r("p",[t._v("要在文件中使用密钥(例如,用于 encyption 的 RSA 公钥),请在键值前加上“@”并提供文件路径。")]),t._v(" "),r("div",{staticClass:"language- extra-class"},[r("pre",{pre:!0,attrs:{class:"language-text"}},[r("code",[t._v("$ spring encrypt mysecret --key @${HOME}/.ssh/id_rsa.pub\nAQAjPgt3eFZQXwt8tsHAVv/QHiY5sI2dRcR+...\n")])])])])}),[],!1,null,null,null);e.default=n.exports}}]);