67.c0e799e4.js 11.5 KB
Newer Older
茶陵後's avatar
茶陵後 已提交
1
(window.webpackJsonp=window.webpackJsonp||[]).push([[67],{493:function(e,t,a){"use strict";a.r(t);var n=a(56),r=Object(n.a)({},(function(){var e=this,t=e.$createElement,a=e._self._c||t;return a("ContentSlotsDistributor",{attrs:{"slot-key":e.$parent.slotKey}},[a("h1",{attrs:{id:"spring-boot-cloud-cli"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#spring-boot-cloud-cli"}},[e._v("#")]),e._v(" Spring Boot Cloud CLI")]),e._v(" "),a("h2",{attrs:{id:"installation"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#installation"}},[e._v("#")]),e._v(" "),a("a",{attrs:{href:"#_installation"}},[e._v("Installation")])]),e._v(" "),a("p",[e._v("To install, make\nsure you have"),a("a",{attrs:{href:"https://github.com/spring-projects/spring-boot",target:"_blank",rel:"noopener noreferrer"}},[e._v("Spring Boot CLI"),a("OutboundLink")],1),e._v("(2.0.0 or better):")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v("$ spring version\nSpring CLI v2.2.3.RELEASE\n")])])]),a("p",[e._v("E.g. for SDKMan users")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v("$ sdk install springboot 2.2.3.RELEASE\n$ sdk use springboot 2.2.3.RELEASE\n")])])]),a("p",[e._v("and install the Spring Cloud plugin")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v("$ mvn install\n$ spring install org.springframework.cloud:spring-cloud-cli:2.2.0.RELEASE\n")])])]),a("table",[a("thead",[a("tr",[a("th"),e._v(" "),a("th",[a("strong",[e._v("Prerequisites:")]),e._v(" to use the encryption and decryption features"),a("br"),e._v("you need the full-strength JCE installed in your JVM (it’s not there by default)."),a("br"),e._v('You can download the "Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files"'),a("br"),e._v("from Oracle, and follow instructions for installation (essentially replace the 2 policy files"),a("br"),e._v("in the JRE lib/security directory with the ones that you downloaded).")])])]),e._v(" "),a("tbody")]),e._v(" "),a("h2",{attrs:{id:"running-spring-cloud-services-in-development"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#running-spring-cloud-services-in-development"}},[e._v("#")]),e._v(" "),a("a",{attrs:{href:"#_running_spring_cloud_services_in_development"}},[e._v("Running Spring Cloud Services in Development")])]),e._v(" "),a("p",[e._v("The Launcher CLI can be used to run common services like Eureka,\nConfig Server etc. from the command line. To list the available\nservices you can do "),a("code",[e._v("spring cloud --list")]),e._v(", and to launch a default set\nof services just "),a("code",[e._v("spring cloud")]),e._v(". To choose the services to deploy,\njust list them on the command line, e.g.")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v("$ spring cloud eureka configserver h2 kafka stubrunner zipkin\n")])])]),a("p",[e._v("Summary of supported deployables:")]),e._v(" "),a("table",[a("thead",[a("tr",[a("th",[e._v("Service")]),e._v(" "),a("th",[e._v("Name")]),e._v(" "),a("th",[e._v("Address")]),e._v(" "),a("th",[e._v("Description")])])]),e._v(" "),a("tbody",[a("tr",[a("td",[e._v("eureka")]),e._v(" "),a("td",[e._v("Eureka Server")]),e._v(" "),a("td",[a("a",{attrs:{href:"http://localhost:8761",target:"_blank",rel:"noopener noreferrer"}},[e._v("http://localhost:8761"),a("OutboundLink")],1)]),e._v(" "),a("td",[e._v("Eureka server for service registration and discovery. All the other services show up in its catalog by default.")])]),e._v(" "),a("tr",[a("td",[e._v("configserver")]),e._v(" "),a("td",[e._v("Config Server")]),e._v(" "),a("td",[a("a",{attrs:{href:"http://localhost:8888",target:"_blank",rel:"noopener noreferrer"}},[e._v("http://localhost:8888"),a("OutboundLink")],1)]),e._v(" "),a("td",[e._v('Spring Cloud Config Server running in the "native" profile and serving configuration from the local directory ./launcher')])]),e._v(" "),a("tr",[a("td",[e._v("h2")]),e._v(" "),a("td",[e._v("H2 Database")]),e._v(" "),a("td",[a("a",{attrs:{href:"http://localhost:9095",target:"_blank",rel:"noopener noreferrer"}},[e._v("http://localhost:9095"),a("OutboundLink")],1),e._v(" (console), jdbc:h2:tcp://localhost:9096/{data}")]),e._v(" "),a("td",[e._v("Relation database service. Use a file path for "),a("code",[e._v("{data}")]),e._v(" (e.g. "),a("code",[e._v("./target/test")]),e._v(") when you connect. Remember that you can add "),a("code",[e._v(";MODE=MYSQL")]),e._v(" or "),a("code",[e._v(";MODE=POSTGRESQL")]),e._v(" to connect with compatibility to other server types.")])]),e._v(" "),a("tr",[a("td",[e._v("kafka")]),e._v(" "),a("td",[e._v("Kafka Broker")]),e._v(" "),a("td",[a("a",{attrs:{href:"http://localhost:9091",target:"_blank",rel:"noopener noreferrer"}},[e._v("http://localhost:9091"),a("OutboundLink")],1),e._v(" (actuator endpoints), localhost:9092")]),e._v(" "),a("td")]),e._v(" "),a("tr",[a("td",[e._v("dataflow")]),e._v(" "),a("td",[e._v("Dataflow Server")]),e._v(" "),a("td",[a("a",{attrs:{href:"http://localhost:9393",target:"_blank",rel:"noopener noreferrer"}},[e._v("http://localhost:9393"),a("OutboundLink")],1)]),e._v(" "),a("td",[e._v("Spring Cloud Dataflow server with UI at /admin-ui. Connect the Dataflow shell to target at root path.")])]),e._v(" "),a("tr",[a("td",[e._v("zipkin")]),e._v(" "),a("td",[e._v("Zipkin Server")]),e._v(" "),a("td",[a("a",{attrs:{href:"http://localhost:9411",target:"_blank",rel:"noopener noreferrer"}},[e._v("http://localhost:9411"),a("OutboundLink")],1)]),e._v(" "),a("td",[e._v("Zipkin Server with UI for visualizing traces. Stores span data in memory and accepts them via HTTP POST of JSON data.")])]),e._v(" "),a("tr",[a("td",[e._v("stubrunner")]),e._v(" "),a("td",[e._v("Stub Runner Boot")]),e._v(" "),a("td",[a("a",{attrs:{href:"http://localhost:8750",target:"_blank",rel:"noopener noreferrer"}},[e._v("http://localhost:8750"),a("OutboundLink")],1)]),e._v(" "),a("td",[e._v("Downloads WireMock stubs, starts WireMock and feeds the started servers with stored stubs. Pass "),a("code",[e._v("stubrunner.ids")]),e._v(" to pass stub coordinates and then go to "),a("code",[e._v("[http://localhost:8750/stubs](http://localhost:8750/stubs)")]),e._v(".")])])])]),e._v(" "),a("p",[e._v('Each of these apps can be configured using a local YAML file with the same name (in the current\nworking directory or a subdirectory called "config" or in '),a("code",[e._v("~/.spring-cloud")]),e._v("). E.g. in "),a("code",[e._v("configserver.yml")]),e._v(" you might want to\ndo something like this to locate a local git repository for the backend:")]),e._v(" "),a("p",[e._v("configserver.yml")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._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")])])]),a("p",[e._v("E.g. in Stub Runner app you could fetch stubs from your local "),a("code",[e._v(".m2")]),e._v(" in the following way.")]),e._v(" "),a("p",[e._v("stubrunner.yml")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v("stubrunner:\n  workOffline: true\n  ids:\n    - com.example:beer-api-producer:+:9876\n")])])]),a("h3",{attrs:{id:"adding-additional-applications"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#adding-additional-applications"}},[e._v("#")]),e._v(" "),a("a",{attrs:{href:"#_adding_additional_applications"}},[e._v("Adding Additional Applications")])]),e._v(" "),a("p",[e._v("Additional applications can be added to "),a("code",[e._v("./config/cloud.yml")]),e._v(" (not"),a("code",[e._v("./config.yml")]),e._v(" because that would replace the defaults), e.g. with")]),e._v(" "),a("p",[e._v("config/cloud.yml")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._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")])])]),a("p",[e._v("when you list the apps:")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v("$ spring cloud --list\nsource sink configserver dataflow eureka h2 kafka stubrunner zipkin\n")])])]),a("p",[e._v("(notice the additional apps at the start of the list).")]),e._v(" "),a("h2",{attrs:{id:"writing-groovy-scripts-and-running-applications"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#writing-groovy-scripts-and-running-applications"}},[e._v("#")]),e._v(" "),a("a",{attrs:{href:"#_writing_groovy_scripts_and_running_applications"}},[e._v("Writing Groovy Scripts and Running Applications")])]),e._v(" "),a("p",[e._v("Spring Cloud CLI has support for most of the Spring Cloud declarative\nfeatures, such as the "),a("code",[e._v("@Enable*")]),e._v(" class of annotations. For example,\nhere is a fully functional Eureka server")]),e._v(" "),a("p",[e._v("app.groovy")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v("@EnableEurekaServer\nclass Eureka {}\n")])])]),a("p",[e._v("which you can run from the command line like this")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v("$ spring run app.groovy\n")])])]),a("p",[e._v("To include additional dependencies, often it suffices just to add the\nappropriate feature-enabling annotation, e.g. "),a("code",[e._v("@EnableConfigServer")]),e._v(","),a("code",[e._v("@EnableOAuth2Sso")]),e._v(" or "),a("code",[e._v("@EnableEurekaClient")]),e._v(". To manually include a\ndependency you can use a "),a("code",[e._v("@Grab")]),e._v(' with the special "Spring Boot" short\nstyle artifact co-ordinates, i.e. with just the artifact ID (no need\nfor group or version information), e.g. to set up a client app to\nlisten on AMQP for management events from the Spring CLoud Bus:')]),e._v(" "),a("p",[e._v("app.groovy")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v("@Grab('spring-cloud-starter-bus-amqp')\n@RestController\nclass Service {\n  @RequestMapping('/')\n  def home() { [message: 'Hello'] }\n}\n")])])]),a("h2",{attrs:{id:"encryption-and-decryption"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#encryption-and-decryption"}},[e._v("#")]),e._v(" "),a("a",{attrs:{href:"#_encryption_and_decryption"}},[e._v("Encryption and Decryption")])]),e._v(" "),a("p",[e._v('The Spring Cloud CLI comes with an "encrypt" and a "decrypt"\ncommand. Both accept arguments in the same form with a key specified\nas a mandatory "--key", e.g.')]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v("$ spring encrypt mysecret --key foo\n682bc583f4641835fa2db009355293665d2647dade3375c0ee201de2a49f7bda\n$ spring decrypt --key foo 682bc583f4641835fa2db009355293665d2647dade3375c0ee201de2a49f7bda\nmysecret\n")])])]),a("p",[e._v('To use a key in a file (e.g. an RSA public key for encyption) prepend\nthe key value with "@" and provide the file path, e.g.')]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v("$ spring encrypt mysecret --key @${HOME}/.ssh/id_rsa.pub\nAQAjPgt3eFZQXwt8tsHAVv/QHiY5sI2dRcR+...\n")])])])])}),[],!1,null,null,null);t.default=r.exports}}]);