10.2 Installing the Spring Boot CLI(安装Spring Boot命令行界面)
1 2 3 4 5 6 7
The Spring Boot CLI (Command Line Interface) is a command line tool that you can use to quickly prototype with Spring. It lets you run Groovy scripts, which means that you have a familiar Java-like syntax without so much boilerplate code. You do not need to use the CLI to work with Spring Boot, but it is definitely the quickest way to get a Spring application off the ground.
Spring Boot CLI(命令行界面)是一个命令行工具,您可以使用它来快速使用Spring进行原型开发 它允许您运行Groovy脚本,这意味着您不需要太多样板代码就能以类似于java的语法进行开发。 尽管您不需要使用CLI去运行Spring Boot ,但这绝对是获得Spring应用程序的最快捷方式
10.2.1 Manual Installation(手动安装)
1 2 3 4 5 6 7 8 9 10
You can download the Spring CLI distribution from the Spring software repository: • spring-boot-cli-2.1.0.BUILD-SNAPSHOT-bin.zip • spring-boot-cli-2.1.0.BUILD-SNAPSHOT-bin.tar.gz Cutting edge snapshot distributions are also available. Once downloaded, follow the INSTALL.txt instructions from the unpacked archive. In summary, there is a spring script (spring.bat for Windows) in a bin/directory in the .zip file. Alternatively, you can use java -jar with the .jar file (the script helps you to be sure that the classpath is set correctly).
SDKMAN! (The Software Development Kit Manager) can be used for managing multiple versions of various binary SDKs, including Groovy and the Spring Boot CLI. Get SDKMAN! from sdkman.io and install Spring Boot by using the following commands:
$ sdk install springboot $ spring --version Spring Boot v2.1.0.BUILD-SNAPSHOT
1 2
If you develop features for the CLI and want easy access to the version you built, use the following commands:
如果您为CLI开发功能并希望轻松访问您创建的版本,请使用以下命令:
1 2 3 4 5
$ sdk install springboot dev /path/to/spring-boot/spring-boot-cli/ target/spring-boot-cli-2.1.0.BUILD-SNAPSHOT-bin/spring-2.1.0.BUILD-SNAPSHOT/ $ sdk default springboot dev $ spring --version Spring CLI v2.1.0.BUILD-SNAPSHOT
1 2
The preceding instructions install a local instance of spring called the dev instance. It points at your target build location, so every time you rebuild Spring Boot,spring is up-to-date. You can see it by running the following command:
================================================================================ Available Springboot Versions ================================================================================ > + dev * 2.1.0.BUILD-SNAPSHOT
================================================================================ + - local version * - installed > - currently in use ================================================================================
If you are on a Mac and use MacPorts, you can install the Spring Boot CLI by using the following command:
如果您使用Mac,并且使用MacPorts,您可以通过以下命令安装Spring Boot CLI
1
$ sudo port install spring-boot-cli
10.2.5 Command-line Completion(命令行完成)
1 2 3 4 5 6 7 8 9
The Spring Boot CLI includes scripts that provide command completion for the BASH and zsh shells. You can source the script (also named spring) in any shell or put it in your personal or system-wide bash completion initialization. On a Debian system, the system-wide scripts are in /shell-completion/bash and all scripts in that directory are executed when a new shell starts. For example, to run the script manually if you have installed by using SDKMAN!, use the following commands:
Spring Boot CLI为BASH和zsh shells提供了命令行完成脚本。您可以在任何shell或者您个人的或者系统范围内的bash中初始化source该脚本。在Debian系统,全系统脚本在/shell-completion/bash,并且所有新建的可执行脚本都在该路径下。比如说,在您已经安装使用SDKMAN的情况下,去手动运行该脚本,使用如下命令:
1 2 3
$ . ~/.sdkman/candidates/springboot/current/shell-completion/bash/spring $ spring <HIT TAB HERE> grab help jar run test version
1 2 3
If you install the Spring Boot CLI by using Homebrew or MacPorts, the command-line completion scripts are automatically registered with your shell.
The first run of your application is slow, as dependencies are downloaded. Subsequent runs are much quicker.
首次运行您的应用会比较慢,因为依赖库需要被下载,以后每次运行会比较快
1 2
Open localhost:8080 in your favorite web browser. You should see the following output:
在您喜爱的浏览器中打开 localhost:8080 ,您将会看到如下的输出:
1
Hello World!
10.3 Upgrading from an Earlier Version of Spring Boot(从一个旧版本升级Spring Boot)
1 2 3 4
If you are upgrading from an earlier release of Spring Boot, check the “migration guide” on the project wiki that provides detailed upgrade instructions. Check also the“release notes” for a list of “new and noteworthy” features for each release.
To upgrade an existing CLI installation, use the appropriate package manager command (for example, brew upgrade) or, if you manually installed the CLI, follow thestandard instructions, remembering to update your PATH environment variable to remove any older references.