提交 56bf0a44 编写于 作者: M Mao

translate installing

上级 d668ce2b
## Installing Spring Boot
Spring Boot can be used with “classic” Java development tools or installed as a command line tool. Either way, you need [Java SDK v1.8](https://www.java.com/) or higher. Before you begin, you should check your current Java installation by using the following command:
```
$ java -version
```
If you are new to Java development or if you want to experiment with Spring Boot, you might want to try the [Spring Boot CLI](https://docs.spring.io/spring-boot/docs/2.6.4/reference/html/getting-started.html#getting-started.installing.cli) (Command Line Interface) first. Otherwise, read on for “classic” installation instructions.
### Installation Instructions for the Java Developer
You can use Spring Boot in the same way as any standard Java library. To do so, include the appropriate `spring-boot-*.jar` files on your classpath. Spring Boot does not require any special tools integration, so you can use any IDE or text editor. Also, there is nothing special about a Spring Boot application, so you can run and debug a Spring Boot application as you would any other Java program.
Although you *could* copy Spring Boot jars, we generally recommend that you use a build tool that supports dependency management (such as Maven or Gradle).
#### Maven Installation
Spring Boot is compatible with Apache Maven 3.3 or above. If you do not already have Maven installed, you can follow the instructions at [maven.apache.org](https://maven.apache.org/).
Tip:
On many operating systems, Maven can be installed with a package manager. If you use OSX Homebrew, try `brew install maven`. Ubuntu users can run `sudo apt-get install maven`. Windows users with [Chocolatey](https://chocolatey.org/) can run `choco install maven` from an elevated (administrator) prompt.
Spring Boot dependencies use the `org.springframework.boot` `groupId`. Typically, your Maven POM file inherits from the `spring-boot-starter-parent` project and declares dependencies to one or more [“Starters”](https://docs.spring.io/spring-boot/docs/2.6.4/reference/html/using.html#using.build-systems.starters). Spring Boot also provides an optional [Maven plugin](https://docs.spring.io/spring-boot/docs/2.6.4/reference/html/build-tool-plugins.html#build-tool-plugins.maven) to create executable jars.
More details on getting started with Spring Boot and Maven can be found in the [Getting Started section](https://docs.spring.io/spring-boot/docs/2.6.4/maven-plugin/reference/htmlsingle/#getting-started) of the Maven plugin’s reference guide.
#### Gradle Installation
Spring Boot is compatible with Gradle 6.8, 6.9, and 7.x. If you do not already have Gradle installed, you can follow the instructions at [gradle.org](https://gradle.org/).
Spring Boot dependencies can be declared by using the `org.springframework.boot` `group`. Typically, your project declares dependencies to one or more [“Starters”](https://docs.spring.io/spring-boot/docs/2.6.4/reference/html/using.html#using.build-systems.starters). Spring Boot provides a useful [Gradle plugin](https://docs.spring.io/spring-boot/docs/2.6.4/reference/html/build-tool-plugins.html#build-tool-plugins.gradle) that can be used to simplify dependency declarations and to create executable jars.
```
Gradle Wrapper
The Gradle Wrapper provides a nice way of “obtaining” Gradle when you need to build a project. It is a small script and library that you commit alongside your code to bootstrap the build process. See docs.gradle.org/current/userguide/gradle_wrapper.html for details.
```
More details on getting started with Spring Boot and Gradle can be found in the [Getting Started section](https://docs.spring.io/spring-boot/docs/2.6.4/gradle-plugin/reference/htmlsingle/#getting-started) of the Gradle plugin’s reference guide.
### Installing the Spring Boot CLI
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](https://groovy-lang.org/) 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 a quick way to get a Spring application off the ground without an IDE.
#### Manual Installation
You can download the Spring CLI distribution from the Spring software repository:
- [spring-boot-cli-2.6.4-bin.zip](https://repo.spring.io/release/org/springframework/boot/spring-boot-cli/2.6.4/spring-boot-cli-2.6.4-bin.zip)
- [spring-boot-cli-2.6.4-bin.tar.gz](https://repo.spring.io/release/org/springframework/boot/spring-boot-cli/2.6.4/spring-boot-cli-2.6.4-bin.tar.gz)
Cutting edge [snapshot distributions](https://repo.spring.io/snapshot/org/springframework/boot/spring-boot-cli/) are also available.
Once downloaded, follow the [INSTALL.txt](https://raw.githubusercontent.com/spring-projects/spring-boot/v2.6.4/spring-boot-project/spring-boot-cli/src/main/content/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).
#### Installation with SDKMAN!
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](https://sdkman.io/) and install Spring Boot by using the following commands:
```
$ sdk install springboot
$ spring --version
Spring CLI v2.6.4
```
If you develop features for the CLI and want access to the version you built, use the following commands:
```
$ sdk install springboot dev /path/to/spring-boot/spring-boot-cli/target/spring-boot-cli-2.6.4-bin/spring-2.6.4/
$ sdk default springboot dev
$ spring --version
Spring CLI v2.6.4
```
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:
```
$ sdk ls springboot
================================================================================
Available Springboot Versions
================================================================================
> + dev
* 2.6.4
================================================================================
+ - local version
* - installed
> - currently in use
================================================================================
```
#### OSX Homebrew Installation
If you are on a Mac and use [Homebrew](https://brew.sh/), you can install the Spring Boot CLI by using the following commands:
```
$ brew tap spring-io/tap
$ brew install spring-boot
```
Homebrew installs `spring` to `/usr/local/bin`.
Note:
If you do not see the formula, your installation of brew might be out-of-date. In that case, run `brew update` and try again.
#### MacPorts Installation
If you are on a Mac and use [MacPorts](https://www.macports.org/), you can install the Spring Boot CLI by using the following command:
```
$ sudo port install spring-boot-cli
```
#### Command-line Completion
The Spring Boot CLI includes scripts that provide command completion for the [BASH](https://en.wikipedia.org/wiki/Bash_(Unix_shell)) and [zsh](https://en.wikipedia.org/wiki/Z_shell) 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:
```
$ . ~/.sdkman/candidates/springboot/current/shell-completion/bash/spring
$ spring <HIT TAB HERE>
grab help jar run test version
```
Note:
If you install the Spring Boot CLI by using Homebrew or MacPorts, the command-line completion scripts are automatically registered with your shell.
#### Windows Scoop Installation
If you are on a Windows and use [Scoop](https://scoop.sh/), you can install the Spring Boot CLI by using the following commands:
```
> scoop bucket add extras
> scoop install springboot
```
Scoop installs `spring` to `~/scoop/apps/springboot/current/bin`.
Note:
If you do not see the app manifest, your installation of scoop might be out-of-date. In that case, run `scoop update` and try again.
#### Quick-start Spring CLI Example
You can use the following web application to test your installation. To start, create a file called `app.groovy`, as follows:
```
@RestController
class ThisWillActuallyRun {
@RequestMapping("/")
String home() {
"Hello World!"
}
}
```
Then run it from a shell, as follows:
```
$ spring run app.groovy
```
Note:
The first run of your application is slow, as dependencies are downloaded. Subsequent runs are much quicker.
Open `localhost:8080` in your favorite web browser. You should see the following output:
```
Hello World!
```
## 安装Spring Boot
Spring Boot 可以与“经典”Java 开发工具一起使用,也可以作为命令行工具安装。无论哪种方式,您都需要[Java SDK v1.8](https://www.java.com/)或更高版本。在开始之前,您应该使用以下命令检查当前的 Java 安装:
```
$ java -version
```
如果您是 Java 开发的新手,或者您想尝试使用 Spring Boot,您可能想先尝试一下[Spring Boot CLI](https://docs.spring.io/spring-boot/docs/2.6.4/reference/html/getting-started.html#getting-started.installing.cli)(命令行界面)。否则,请继续阅读“经典”安装说明。
### Java 开发人员安装说明
您可以像使用任何标准 Java 库一样使用 Spring Boot。为此,请`spring-boot-*.jar`在类路径中包含适当的文件。Spring Boot 不需要任何特殊工具集成,因此您可以使用任何 IDE 或文本编辑器。此外,Spring Boot 应用程序没有什么特别之处,因此您可以像运行任何其他 Java 程序一样运行和调试 Spring Boot 应用程序。
虽然您*可以*复制 Spring Boot jar,但我们通常建议您使用支持依赖管理的构建工具(例如 Maven 或 Gradle)。
#### Maven Installation
Spring Boot 兼容 Apache Maven 3.3 或更高版本。如果您还没有安装 Maven,您可以按照[maven.apache.org](https://maven.apache.org/)上的说明进行操作。
提示:
在许多操作系统上,可以使用包管理器安装 Maven。如果您使用 OSX Homebrew,请尝试`brew install maven`. Ubuntu 用户可以运行`sudo apt-get install maven`. [使用Chocolatey](https://chocolatey.org/)的Windows 用户可以`choco install maven`从提升的(管理员)提示符下运行。
Spring Boot 依赖项使用`org.springframework.boot` `groupId`. 通常,您的 Maven POM 文件继承自`spring-boot-starter-parent`项目并声明对一个或多个[“Starters”](https://docs.spring.io/spring-boot/docs/2.6.4/reference/html/using.html#using.build-systems.starters)的依赖关系。Spring Boot 还提供了一个可选的[Maven 插件](https://docs.spring.io/spring-boot/docs/2.6.4/reference/html/build-tool-plugins.html#build-tool-plugins.maven)来创建可执行的 jar。
有关 Spring Boot 和 Maven 入门的更多详细信息,请参阅 Maven 插件参考指南的[入门部分](https://docs.spring.io/spring-boot/docs/2.6.4/maven-plugin/reference/htmlsingle/#getting-started)
#### 摇篮安装
Spring Boot 与 Gradle 6.8、6.9 和 7.x 兼容。如果您尚未安装 Gradle,可以按照[gradle.org](https://gradle.org/)上的说明进行操作。
Spring Boot 依赖项可以使用`org.springframework.boot` `group`. 通常,您的项目声明对一个或多个[“Starters”](https://docs.spring.io/spring-boot/docs/2.6.4/reference/html/using.html#using.build-systems.starters)的依赖关系。Spring Boot 提供了一个有用的[Gradle 插件](https://docs.spring.io/spring-boot/docs/2.6.4/reference/html/build-tool-plugins.html#build-tool-plugins.gradle),可用于简化依赖声明和创建可执行 jar。
```
Gradle 包装器
当您需要构建项目时,Gradle Wrapper 提供了一种“获取” Gradle 的好方法。它是一个小型脚本和库,您可以将其与代码一起提交以引导构建过程。有关详细信息,请参阅docs.gradle.org/current/userguide/gradle_wrapper.html。
```
有关 Spring Boot 和 Gradle 入门的更多详细信息,请参阅 Gradle 插件参考指南的[入门部分](https://docs.spring.io/spring-boot/docs/2.6.4/gradle-plugin/reference/htmlsingle/#getting-started)
### 安装 Spring Boot CLI
Spring Boot CLI(命令行界面)是一个命令行工具,您可以使用它来快速使用 Spring 进行原型设计。它允许您运行[Groovy](https://groovy-lang.org/)脚本,这意味着您拥有熟悉的类似 Java 的语法,而无需太多样板代码。
您无需使用 CLI 即可使用 Spring Boot,但它是一种无需 IDE 即可快速启动 Spring 应用程序的方法。
#### 手动安装
您可以从 Spring 软件存储库下载 Spring CLI 发行版:
- [spring-boot-cli-2.6.4-bin.zip](https://repo.spring.io/release/org/springframework/boot/spring-boot-cli/2.6.4/spring-boot-cli-2.6.4-bin.zip)
- [spring-boot-cli-2.6.4-bin.tar.gz](https://repo.spring.io/release/org/springframework/boot/spring-boot-cli/2.6.4/spring-boot-cli-2.6.4-bin.tar.gz)
还提供最先进 的[快照分发。](https://repo.spring.io/snapshot/org/springframework/boot/spring-boot-cli/)
下载后,按照解压缩存档中的[INSTALL.txt](https://raw.githubusercontent.com/spring-projects/spring-boot/v2.6.4/spring-boot-project/spring-boot-cli/src/main/content/INSTALL.txt)说明进行操作。总之,文件中的目录中有一个`spring`脚本(`spring.bat`适用于 Windows)。或者,您可以使用该文件(该脚本可帮助您确保类路径设置正确)。`bin/``.zip``java -jar``.jar`
#### 使用 SDKMAN 安装!
开发者!(软件开发工具包管理器)可用于管理各种二进制 SDK 的多个版本,包括 Groovy 和 Spring Boot CLI。获取 SDKMAN!从[sdkman.io](https://sdkman.io/)并使用以下命令安装 Spring Boot:
```
$ sdk install springboot
$ spring --version
Spring CLI v2.6.4
```
如果您为 CLI 开发功能并希望访问您构建的版本,请使用以下命令:
```
$ sdk install springboot dev /path/to/spring-boot/spring-boot-cli/target/spring-boot-cli-2.6.4-bin/spring-2.6.4/
$ sdk default springboot dev
$ spring --version
Spring CLI v2.6.4
```
前面的说明安装了一个`spring`称为实例的本地`dev`实例。它指向您的目标构建位置,因此每次您重建 Spring Boot 时,`spring`它都是最新的。
您可以通过运行以下命令来查看它:
```
$ sdk ls springboot
================================================================================
Available Springboot Versions
================================================================================
> + dev
* 2.6.4
================================================================================
+ - local version
* - installed
> - currently in use
================================================================================
```
#### OSX Homebrew 安装
如果您在 Mac 上使用[Homebrew](https://brew.sh/),则可以使用以下命令安装 Spring Boot CLI:
```
$ brew tap spring-io/tap
$ brew install spring-boot
```
Homebrew 安装`spring``/usr/local/bin`.
笔记:
如果您没有看到公式,则您的 brew 安装可能已过时。在这种情况下,运行`brew update`并重试。
#### MacPorts 安装
如果您在 Mac 上并使用[MacPorts](https://www.macports.org/),则可以使用以下命令安装 Spring Boot CLI:
```
$ sudo port install spring-boot-cli
```
#### 命令行完成
[Spring Boot CLI 包括为BASH](https://en.wikipedia.org/wiki/Bash_(Unix_shell))和[zsh](https://en.wikipedia.org/wiki/Z_shell) shell提供命令完成的脚本。您可以`source`将脚本(也称为`spring`)放在任何 shell 中,也可以将其放入您的个人或系统范围的 bash 完成初始化中。在 Debian 系统上,系统范围的脚本在其中,`/shell-completion/bash`并且该目录中的所有脚本都会在新的 shell 启动时执行。例如,如果您已使用 SDKMAN! 安装,要手动运行脚本,请使用以下命令:
```
$ . ~/.sdkman/candidates/springboot/current/shell-completion/bash/spring
$ spring <HIT TAB HERE>
grab help jar run test version
```
笔记:
如果您使用 Homebrew 或 MacPorts 安装 Spring Boot CLI,命令行完成脚本会自动注册到您的 shell。
#### Windows 独家新闻安装
如果您在 Windows 上并使用[Scoop](https://scoop.sh/),则可以使用以下命令安装 Spring Boot CLI:
```
> scoop bucket add extras
> scoop install springboot
```
Scoop 安装`spring``~/scoop/apps/springboot/current/bin`.
笔记:
如果您没有看到应用清单,则您安装的 scoop 可能已过期。在这种情况下,运行`scoop update`并重试。
#### 快速入门 Spring CLI 示例
您可以使用以下 Web 应用程序来测试您的安装。首先,创建一个名为 的文件`app.groovy`,如下所示:
```
@RestController
class ThisWillActuallyRun {
@RequestMapping("/")
String home() {
"Hello World!"
}
}
```
然后从 shell 运行它,如下所示:
```
$ spring run app.groovy
```
笔记:
您的应用程序的第一次运行很慢,因为下载了依赖项。随后的运行要快得多。
`localhost:8080`在您喜欢的网络浏览器中打开。您应该看到以下输出:
```
Hello World!
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册