Spring Boot CLI 中文文档

本文为官方文档直译版本。原文链接

引言

Spring Boot CLI 是一种命令行工具,可用于从 start.spring.io 引导新项目或编码密码。

安装 CLI

Spring Boot CLI(命令行界面)可通过使用 SDKMAN!(SDK 管理器)或使用 Homebrew 或 MacPorts(如果您是 OSX 用户)手动安装。有关全面的安装说明,请参见 “入门” 部分中的 getting-started.html

使用 CLI

安装 CLI 后,在命令行输入 spring 并按 Enter 即可运行。如果不带任何参数运行 spring,会显示如下帮助屏幕:

$ spring
usage: spring [--help] [--version]
       <command> [<args>]

Available commands are:
可用命令包括:

  init [options] [location]
    Initialize a new project using Spring Initializr (start.spring.io)
    使用 Spring Initializr(start.spring.io)初始化新项目

  encodepassword [options] <password to encode>
    Encode a password for use with Spring Security
    为密码编码,以便与 Spring Security 一起使用

  shell
    Start a nested shell
    启动嵌套 shell

Common options:

  --debug Verbose mode
    Print additional status information for the command you are running
    打印正在运行的命令的其他状态信息


See 'spring help <command>' for more information on a specific command.
有关特定命令的更多信息,请参阅 "spring help <command>"

如下面的示例所示,您可以输入 spring help 获取任何支持命令的详细信息:

$ spring help init
spring init - Initialize a new project using Spring Initializr (start.spring.io)
            	使用 Spring Initializr(start.spring.io)初始化新项目

usage: spring init [options] [location]

Option                       Description
------                       -----------
-a, --artifact-id <String>   Project coordinates; infer archive name (for
                               example 'test')
                             项目坐标;推断档案名称(例如例如 "测试")
                             
-b, --boot-version <String>  Spring Boot version (for example '1.2.0.RELEASE')
                             Spring Boot 版本(例如 "1.2.0.RELEASE")。
                             
--build <String>             Build system to use (for example 'maven' or 'gradle')
															(default: maven)
                             要使用的构建系统(例如"maven""gradle")(默认:maven)
                             
-d, --dependencies <String>  Comma-separated list of dependency identifiers to
                               include in the generated project
                             以逗号分隔的依赖项标识符列表。包含在生成的项目中
                             
--description <String>       Project description
                          	 项目描述
                             
-f, --force                  Force overwrite of existing files
                          	 强制覆盖已有文件
                             
--format <String>            Format of the generated content (for example
                               'build' for a build file, 'project' for a
                               project archive) (default: project)
                             生成内容的格式
                             (例如'build'表示构建文件,'project'表示项目存档)
                             (默认:项目)
                             
-g, --group-id <String>      Project coordinates (for example 'org.test')
                             项目坐标(例如 "org.test")
                             
-j, --java-version <String>  Language level (for example '1.8')
                             语言级别(例如 "1.8")
                             
-l, --language <String>      Programming language  (for example 'java')
                             编程语言(例如 "java"--list                       List the capabilities of the service. Use it to
                               discover the dependencies and the types that are
                               available
                             列出服务的功能。用它来发现依赖关系和可用类型可用类型
                             
-n, --name <String>          Project name; infer application name
                          	 项目名称;推断应用名称
                             
-p, --packaging <String>     Project packaging (for example 'jar')
                             项目打包(例如 "jar")
                             
--package-name <String>      Package name
                          	 包名称
                             
-t, --type <String>          Project type. Not normally needed if you use --
                               build and/or --format. Check the capabilities of
                               the service (--list) for more details
                             项目类型。如果使用 --build 和/或 --format 
                             查看服务的功能(--list)以了解更多详情
                             
--target <String>            URL of the service to use (default: https://start.
                               spring.io)
                             要使用的服务的 URL(默认值:https://start.spring.io)
                             
-v, --version <String>       Project version (for example '0.0.1-SNAPSHOT')
                             项目版本(例如 "0.0.1-SNAPSHOT")
                             
-x, --extract                Extract the project archive. Inferred if a
                               location is specified without an extension
                             提取项目存档。如果指定的指定的位置没有扩展名

examples:

    To list all the capabilities of the service:
    列出服务的全部功能:
        $ spring init --list

    To creates a default project:
    创建默认项目:
        $ spring init

    To create a web my-app.zip:
    创建web my-app.zip:
        $ spring init -d=web my-app.zip

    To create a web/data-jpa gradle project unpacked:
    创建已解压的 web/data-jpa gradle 项目:
        $ spring init -d=web,jpa --build=gradle my-dir

version命令提供了一种快速方法来检查你正在使用的 Spring Boot 版本,如下所示:

$ spring version
Spring CLI v3.2.1

初始化新项目

如下面的示例所示,init 命令可让你在不离开 shell 的情况下使用 start.spring.io 创建一个新项目:

$ spring init --dependencies=web,data-jpa my-project
Using service at https://start.spring.io
Project extracted to '/Users/developer/example/my-project'

上例创建了一个 my-project 目录,其中包含一个基于 Maven 的项目,该项目使用了 spring-boot-starter-webspring-boot-starter-data-jpa。你可以使用 --list 标志列出服务的功能,如下例所示:

$ spring init --list
=======================================
Capabilities of https://start.spring.io
=======================================

Available dependencies:
-----------------------
actuator - Actuator: Production ready features to help you monitor and manage your application
...
web - Web: Support for full-stack web development, including Tomcat and spring-webmvc
websocket - Websocket: Support for WebSocket development
ws - WS: Support for Spring Web Services

Available project types:
------------------------
gradle-build -  Gradle Config [format:build, build:gradle]
gradle-project -  Gradle Project [format:project, build:gradle]
maven-build -  Maven POM [format:build, build:maven]
maven-project -  Maven Project [format:project, build:maven] (default)

...

init 命令支持许多选项。详情请查看help输出。例如,下面的命令创建了一个使用 Java 17 和 war 打包的 Gradle 项目:

$ spring init --build=gradle --java-version=17 --dependencies=websocket --packaging=war sample-app.zip
Using service at https://start.spring.io
Content saved to 'sample-app.zip'

使用嵌入式 Shell

Spring Boot 包含 BASH 和 zsh shell 的命令行完成脚本。如果您不使用这两种 shell(也许您是 Windows 用户),则可以使用 shell 命令启动集成 shell,如下例所示:

$ spring shell
Spring Boot (v3.2.1)
Hit TAB to complete. Type \'help' and hit RETURN for help, and \'exit' to quit.

在嵌入式 shell 中,你可以直接运行其他命令:

$ version
Spring CLI v3.2.1

嵌入式 shell 支持 ANSI 颜色输出和tab补全。如果需要运行本地命令,可以使用 ! 前缀。要退出嵌入式 shell,请按 ctrl-c

  • 17
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
spring boot中文文档,从安装到部署。 I. Spring Boot文件 1.关于文档 2.获得帮助 3.第一步 4.使用Spring Boot 5.了解Spring Boot功能 6.转向生产 7.高级主题 II。入门 8.介绍Spring Boot 9.系统要求 9.1.Servlet容器 10.安装Spring Boot 10.1.Java Developer的安装说明 10.1.1.Maven安装 10.1.2.Gradle安装 10.2.安装Spring Boot CLI 10.2.1.手动安装 10.2.2.使用SDKMAN安装! 10.2.3.OSX Homebrew安装 10.2.4.MacPorts安装 10.2.5.命令行完成 10.2.6.Windows Scoop安装 10.2.7.快速启动Spring CLI示例 10.3.从早期版本的Spring Boot升级 11.开发您的第一个Spring Boot应用程序 11.1.创建POM 11.2.添加Classpath依赖项 11.3.编写代码 11.3.1.@RestController和@RequestMapping Annotations 11.3.2.@EnableAutoConfiguration注释 11.3.3.“主要”方法 11.4.运行示例 11.5.创建一个可执行的Jar 12.接下来要阅读的内容 III。使用Spring Boot 13.构建系统 13.1.依赖管理 13.2.Maven 13.2.1.继承Starter Parent 13.2.2.在没有父POM的情况下使用Spring Boot 13.2.3.使用Spring Boot Maven插件 13.3.Gradle 13.4.Ant 13.5.Starters 14.构建您的代码 14.1.使用“默认”包 14.2.找到主应用程序类 15.配置类 15.1.导入其他配置类 15.2.导入XML配置 16.自动配置 16.1.逐步更换自动配置 16.2.禁用特定的自动配置类 17. Spring Beans和依赖注入 18.使用@SpringBootApplication Annotation 19.运行您的应用程序 19.1.从IDE运行 19.2.作为打包应用程序运行 19.3.使用Maven插件 19.4.使用Gradle插件 19.5.热插拔 20.开发人员工具 20.1.Property默认值 20.2.自动重启 20.2.1.记录条件评估中的更改 20.2.2.不包括资源 20.2.3.观看其他路径 20.2.4.禁用重启 20.2.5.使用触发器文件 20.2.6.自定义重新启动类加载器 20.2.7.已知限制 20.3.LiveReload 20.4.全局设置 20.5.远程应用 20.5.1.运行远程客户端应用程序 20.5.2.远程更新 21.包装您的生产

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值