使用Spring Boot CLI的Spring Boot Initilizr

This is continuation to my two previous posts. Before reading this post, please go through my previous posts at “Spring Boot Initilizr Web Interface” and “Spring Boot Initilizr With IDEs or IDE Plugins”.

这是我之前两篇文章的延续。 在阅读本文之前,请仔细阅读我以前的文章“ Spring Boot Initilizr Web Interface ”和“带有IDE或IDE插件的Spring Boot Initilizr”

Spring Boot Initilizr is used to quick start new Spring Boot Maven/Gradle projects within no time. It generates initial project structure and build scripts to reduce Development time.

Spring Boot Initilizr用于快速启动新的Spring Boot Maven / Gradle项目。 它生成初始项目结构并构建脚本以减少开发时间。

As we discussed in my previous post, Spring Boot Initilizr is available in the following forms:

正如我们在上一篇文章中讨论的那样,Spring Boot Initilizr具有以下形式:

  1. Spring Boot Initilizr With Web Interface

    具有Web界面的Spring Boot Initilizr
  2. Spring Boot Initilizr With IDEs/IDE Plugins

    具有IDE / IDE插件的Spring Boot Initilizr
  3. Spring Boot Initilizr With Spring Boot CLI

    使用Spring Boot CLI的Spring Boot Initilizr
  4. Spring Boot Initilizr With ThirdParty Tools

    带有第三方工具的Spring Boot Initilizr

Now we are going to discuss on How to bootstrap Spring Applications using “Spring Boot Initilizr With Spring Boot CLI” option.

现在,我们将讨论如何使用“带有Spring Boot CLI的Spring Boot Initilizr”选项来引导Spring应用程序。

使用Spring Boot CLI的Spring Boot Initilizr (Spring Boot Initilizr With Spring Boot CLI)

Please go through this post first “Spring Boot CLI Basics” to setup Spring Boot CLI software. Spring Boot CLI provides a “spring init” command to bootstrap Spring Applications.

请首先阅读这篇文章“ Spring Boot CLI基础知识”以设置Spring Boot CLI软件。 Spring Boot CLI提供了一个“ spring init”命令来引导Spring应用程序。

I have downloaded Spring Boot CLI zip from “https://start.spring.io” and installed this Software at “D:\spring-boot-cli-1.2.3.RELEASE”.

我已经从“ https://start.spring.io”下载了Spring Boot CLI zip,并将此软件安装在“ D:\ spring-boot-cli-1.2.3.RELEASE”。

Set the following System Variable:

设置以下系统变量:

PATH=D:\spring-boot-cli-1.2.3.RELEASE\bin;%PATH%

“spring init” command

“ spring init”命令

The “spring init” command is easy to use command from Spring Boot CLI Component. It uses “Spring Initilizr Service” hosted at “https://start.spring.io” (default, we can specify the the target URL also. We will discuss this in next section.) to bootstrap Spring or Spring Boot Applications by using Spring Boot CLI component.

Spring Boot CLI组件中的“ spring init”命令易于使用。 它使用托管在“ https://start.spring.io”上的“ Spring Initilizr服务”(默认情况下,我们也可以指定目标URL。我们将在下一部分中进行讨论。)通过使用以下命令引导Spring或Spring Boot应用程序Spring Boot CLI组件。

“spring init” syntax

“ spring init”语法

spring init [options] [location]

Here “options” are command options and “location” is specified our file system location to create new Spring Boot Project. We will discuss command options one by one in detail soon.

这里的“选项”是命令选项,“位置”是我们文件系统的位置,用于创建新的Spring Boot项目。 我们将很快详细讨论命令选项。

Use “spring help init” command to see all available “spring init” command options as shown below.

使用“ spring help init”命令查看所有可用的“ spring init”命令选项,如下所示。

spring help init

“ spring init”命令示例 (The “spring init” command examples)

Now we will explore “spring init” command options one by one with some suitable examples. Open CMD(Command Prompt) at your IDE Workspace(My Workspace is at D:\RamWorkspaces\SpringSTSBootWorkspace2) and execute the following examples.

现在,我们将通过一些合适的示例逐一探讨“ spring init”命令选项。 在IDE工作区(我的工作区位于D:\ RamWorkspaces \ SpringSTSBootWorkspace2)中打开CMD(命令提示符),然后执行以下示例。

Example-1:- To create Spring Boot project with default settings:

Example-1:-要使用默认设置创建Spring Boot项目:

spring init

It creates new Spring Boot Project zip file as “demo.zip” at current working directory with default settings.

它使用默认设置在当前工作目录中创建一个新的Spring Boot Project zip文件,名为“ demo.zip”。

NOTE:- “spring init” Default settings:

注意:- “ spring init”默认设置:

  1. Default Build tool is “maven”.

    默认的构建工具是“ maven”。
  2. Default Spring Initilizr service target URL: https://start.spring.io

    默认的Spring Initilizr服务目标URL:https://start.spring.io
  3. Default project name: “demo”

    默认项目名称:“ demo”
  4. Default maven type: “jar”

    默认行家类型:“ jar”
  5. Default Spring Boot dependencies added to build script file:

    默认的Spring Boot依赖项已添加到构建脚本文件中:
  6. <dependencies>
    	<dependency>
    		<groupId>org.springframework.boot</groupId>
    		<artifactId>spring-boot-starter</artifactId>
    	</dependency>
    		
    	<dependency>
    		<groupId>org.springframework.boot</groupId>
    		<artifactId>spring-boot-starter-test</artifactId>
    		<scope>test</scope>
    	</dependency>
    </dependencies>
  7. Default Maven artifacts:

    默认的Maven工件:
  8. <groupId>org.test</groupId>
        <artifactId>demo</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <packaging>jar</packaging>
        <name>demo</name>

Example-2:- To create Spring Boot Project with required Dependencies and Project name

Example-2:-使用所需的依赖关系和项目名称创建Spring Boot项目

spring init -d=web,data-jpa,jms,ws SpringMVCMavenToolProject.zip

It creates a packed Spring Boot WebApplication with JPA,JMS and WS capabilities.

它创建具有JPA,JMS和WS功能的打包Spring Boot WebApplication。

Here “-d” option means we can list out all required capabilities with comma separated values.
“SpringMVCMavenToolProject.zip” is a Project name and zip file created with that name in the current working directory.

这里的“ -d”选项意味着我们可以列出所有必需的功能,并用逗号分隔值。
“ SpringMVCMavenToolProject.zip”是项目名称和在当前工作目录中使用该名称创建的zip文件。

Example-3:-To create Spring Boot Project with required Dependencies and Project name for Gradle Build Tool.

示例3:-使用Gradle Build Tool创建具有所需依赖关系和项目名称的Spring Boot项目。

spring init -d=web,data-jpa,jms,ws --build=gradle -p=war SpringMVCGradleToolProject

It creates a unpacked Spring Boot WebApplication with JPA,JMS and WS capabilities for Gradle build tool.

它为Gradle构建工具创建了具有JPA,JMS和WS功能的解压Spring Boot WebApplication。

  • “-d” option means we can list out all required capabilities with comma separated values.

    “ -d”选项意味着我们可以用逗号分隔的值列出所有必需的功能。
  • “–build” option specifies required build tool. It accepts two values: maven(Default) and gradle.

    “ –build”选项指定所需的构建工具。 它接受两个值:maven(Default)和gradle。
  • “SpringMVCGradleToolProject” is a Project name created in the current working directory.

    “ SpringMVCGradleToolProject”是在当前工作目录中创建的项目名称。
  • “-p” or “–packaging” option specifies the packaging type. Default value is “jar”.

    “ -p”或“ -packaging”选项指定包装类型。 默认值为“ jar”。

Example-4:-To create Spring Boot Project with required Dependencies and Project name for Maven Build Tool.

示例4:-创建带有Maven Build Tool所需的依赖关系和项目名称的Spring Boot项目。

spring init -d=web,jdbc,ws,cloud-aws,h2 --build=maven 
            --packaging=war SpringMVCMavenToolProject.zip

It creates a packed Spring Boot WebApplication with JDBC,AWS Cloud and WS capabilities for Maven build tool.

它为Maven构建工具创建了一个具有JDBC,AWS Cloud和WS功能的打包Spring Boot WebApplication。

  • “-d” option means we can list out all required capabilities with comma separated values.

    “ -d”选项意味着我们可以用逗号分隔的值列出所有必需的功能。
  • “–build” option specifies required build tool. It accepts two values: maven(Default) and gradle.

    “ –build”选项指定所需的构建工具。 它接受两个值:maven(Default)和gradle。
  • “SpringMVCMavenToolProject” is a Project name created in the current working directory.

    “ SpringMVCMavenToolProject”是在当前工作目录中创建的项目名称。
  • “-p” or “–packaging” option specifies the packaging type. Default value is “jar”. It accepts “pom, jar, war, ear, rar, par”

    “ -p”或“ -packaging”选项指定包装类型。 默认值为“ jar”。 它接受“ pom,jar,war,ear,rar,par”

Example-5:-To create Spring Boot Project with required Dependencies and Project name for Maven Build Tool with specified Spring Boot and Java Versions.

示例5:-为具有指定Spring Boot和Java版本的Maven Build Tool创建具有所需依赖关系和项目名称的Spring Boot项目。

By default, “spring init” command will pickup “System Variables” and take appropriate Spring Boot and Java Versions. However it is possible to specify Spring Boot and Java Versions.

默认情况下,“ spring init”命令将提取“系统变量”并采用适当的Spring Boot和Java版本。 但是,可以指定Spring Boot和Java版本。

My Windows system is configured with Java Version = 1.8 and Spring Boot version = 1.2.3.RELEASE. However I would like to change them in creating new Spring Boot project as shown below.

我的Windows系统配置了Java版本= 1.8和Spring Boot版本= 1.2.3.RELEASE。 但是我想在创建新的Spring Boot项目时更改它们,如下所示。

spring init -d=web,jdbc,ws,cloud-aws,h2 --build=maven 
            --java-version=1.7
            --boot-version=1.2.5.RELEASE
            -packaging=war SpringMVCMavenToolProject.zip

It creates a packed Spring Boot WebApplication with JDBC,AWS Cloud and WS capabilities for Maven build tool with Java 1.7 and Spring Boot 1.2.5.RELEASE.

它使用Java 1.7和Spring Boot 1.2.5.RELEASE为具有Maven构建工具的JDBC,AWS Cloud和WS功能创建打包的Spring Boot WebApplication。

  • “-j” or “–java-version” option is used to specify Java Version like 1.7,1.8 etc.

    “ -j”或“ –java-version”选项用于指定Java版本,例如1.7、1.8等。
  • “-b” or “–boot-version” option is used to specify Spring Boot Framework version like 1.2.5.RELEASE,1.3.0.M1 etc.

    “ -b”或“ –boot-version”选项用于指定Spring Boot Framework版本,例如1.2.5.RELEASE,1.3.0.M1等。
  • “-d” option means we can list out all required capabilities with comma separated values.

    “ -d”选项意味着我们可以用逗号分隔的值列出所有必需的功能。
  • “–build” option specifies required build tool. It accepts two values: maven(Default) and gradle.

    “ –build”选项指定所需的构建工具。 它接受两个值:maven(Default)和gradle。
  • “SpringMVCMavenToolProject” is a Project name created in the current working directory.

    “ SpringMVCMavenToolProject”是在当前工作目录中创建的项目名称。
  • “-p” or “–packaging” option specifies the packaging type. Default value is “jar”. It accepts “pom, jar, war, ear, rar, par”

    “ -p”或“ -packaging”选项指定包装类型。 默认值为“ jar”。 它接受“ pom,jar,war,ear,rar,par”

NOTE:-
When we execute “spring init” command, we can observe the following message saying that it is going to connect “Spring Boot Initilizr Default Service”.

注意:-
当我们执行“ spring init”命令时,我们可以观察到以下消息,该消息将连接“ Spring Boot Initilizr默认服务”。

Using service at https://start.spring.io

In the same way, we can use other “spring init” options to explore them. For example, “–force” to force update already existing same project name with updates to avoid errors.

同样,我们可以使用其他“ spring init”选项进行探索。 例如,“ – force”强制使用更新来更新已经存在的相同项目名称,以避免错误。

NOTE:-
We can extract those zip files created using “spring init” command and import these projects into our favorite Spring IDEs(For example:- Spring STS Suite) and continue to develop our project related requirements.

注意:-
我们可以提取使用“ spring init”命令创建的zip文件,并将这些项目导入到我们最喜欢的Spring IDE(例如:Spring STS Suite)中,然后继续开发与项目相关的需求。

We will develop some applications by using these Spring Boot projects to enhance some functionality in my coming posts.

我们将通过使用这些Spring Boot项目来开发一些应用程序,以增强我的后续文章中的某些功能。

The following section has a list of supported build options.

以下部分列出了受支持的构建选项。

+--------+----------------------------------------------------------------------+
| Id     | Description                                                          |
+--------+----------------------------------------------------------------------+
| maven  | Creates a Maven project with pom.xml file for Maven build tool       |
| gradle | Creates a Maven project with build.gradle file for Gradle build tool |
+-------------------------------------------------------------------------------+

Default build parameter value is “maven”

默认的构建参数值为“ maven”

The following section has a list of supported identifiers for the comma-separated list of “dependencies”.

下一节列出了以逗号分隔的“依赖项”列表的受支持标识符的列表。

+-------------------------+-----------------------------------------------------------------------------------------------+------------------+
| Id                      | Description                                                                                   | Required version |
+-------------------------+-----------------------------------------------------------------------------------------------+------------------+
| actuator                | Production ready features to help you monitor and manage your application                     |                  |
| amqp                    | Support for the Advanced Message Queuing Protocol via spring-rabbit                           |                  |
| aop                     | Support for aspect-oriented programming including spring-aop and AspectJ                      |                  |
| batch                   | Support for Spring Batch including HSQLDB database                                            |                  |
| cache                   | Support for Spring's Cache abstraction                                                        | >= 1.3.0.M1      |
| cloud-aws               | Support for spring-cloud-aws                                                                  | >= 1.2.3.RELEASE |
| cloud-aws-jdbc          | Support for spring-cloud-aws-jdbc                                                             | >= 1.2.3.RELEASE |
| cloud-aws-messaging     | Support for spring-cloud-aws-messaging                                                        | >= 1.2.3.RELEASE |
| cloud-bus-amqp          | Support for spring-cloud-bus-amqp                                                             | >= 1.2.3.RELEASE |
| cloud-config-client     | Support for spring-cloud-config Client                                                        | >= 1.2.3.RELEASE |
| cloud-config-server     | Support for spring-cloud-config Server                                                        | >= 1.2.3.RELEASE |
| cloud-connectors        | Simplifies connecting to services in cloud platforms                                          | >= 1.2.0.RELEASE |
| cloud-eureka            | Support for spring-cloud-netflix Eureka                                                       | >= 1.2.3.RELEASE |
| cloud-eureka-server     | Support for spring-cloud-netflix Eureka Server                                                | >= 1.2.3.RELEASE |
| cloud-feign             | Support for spring-cloud-netflix Feign                                                        | >= 1.2.3.RELEASE |
| cloud-hystrix           | Support for spring-cloud-netflix Hystrix                                                      | >= 1.2.3.RELEASE |
| cloud-hystrix-dashboard | Support for spring-cloud-netflix Hystrix Dashboard                                            | >= 1.2.3.RELEASE |
| cloud-oauth2            | Support for spring-cloud-security OAuth2                                                      | >= 1.2.3.RELEASE |
| cloud-ribbon            | Support for spring-cloud-netflix Ribbon                                                       | >= 1.2.3.RELEASE |
| cloud-security          | Support for spring-cloud-security                                                             | >= 1.2.3.RELEASE |
| cloud-starter           | Support for spring-cloud-context (e.g. Bootstrap context and @RefreshScope)                   | >= 1.2.3.RELEASE |
| cloud-turbine           | Support for spring-cloud-netflix Turbine                                                      | >= 1.2.3.RELEASE |
| cloud-turbine-amqp      | Support for spring-cloud-netflix Turbine AMQP                                                 | >= 1.2.3.RELEASE |
| cloud-zuul              | Support for spring-cloud-netflix Zuul                                                         | >= 1.2.3.RELEASE |
| data-elasticsearch      | Support for the Elasticsearch search and analytics engine including spring-data-elasticsearch |                  |
| data-gemfire            | Support for the GemFire distributed data store including spring-data-gemfire                  |                  |
| data-jpa                | Support for the Java Persistence API including spring-data-jpa, spring-orm and Hibernate      |                  |
| data-mongodb            | Support for the MongoDB NoSQL Database, including spring-data-mongodb                         |                  |
| data-rest               | Support for exposing Spring Data repositories over REST via spring-data-rest-webmvc           |                  |
| data-solr               | Support for the Apache Solr search platform, including spring-data-solr                       |                  |
| derby                   | Support for the Apache Derby database (with embedded support)                                 | >= 1.2.2.RELEASE |
| devtools                | Support for Spring Boot Development Tools.                                                    | >= 1.3.0.M1      |
| freemarker              | Support for the FreeMarker templating engine                                                  |                  |
| groovy-templates        | Support for the Groovy templating engine                                                      |                  |
| h2                      | Support for the H2 database (with embedded support)                                           |                  |
| hateoas                 | Support for HATEOAS-based RESTful services                                                    | >= 1.2.2.RELEASE |
| hornetq                 | Support for Java Message Service API via HornetQ                                              |                  |
| hsql                    | Support for the HSQLDB database (with embedded support)                                       |                  |
| integration             | Support for common spring-integration modules                                                 |                  |
| jdbc                    | Support for JDBC databases                                                                    |                  |
| jersey                  | Support for the Jersey RESTful Web Services framework                                         | >= 1.2.0.RELEASE |
| jta-atomikos            | Support for JTA distributed transactions via Atomikos                                         | >= 1.2.0.M1      |
| jta-bitronix            | Support for JTA distributed transactions via Bitronix                                         | >= 1.2.0.M1      |
| mail                    | Support for javax.mail                                                                        | >= 1.2.0.RC1     |
| mobile                  | Support for spring-mobile                                                                     |                  |
| mustache                | Support for the Mustache templating engine                                                    | >= 1.2.2.RELEASE |
| mysql                   | Support for the MySQL jdbc driver                                                             |                  |
| postgresql              | Support for the PostgreSQL jdbc driver                                                        |                  |
| redis                   | Support for the REDIS key-value data store, including spring-redis                            |                  |
| remote-shell            | Support for CRaSH                                                                             |                  |
| security                | Support for spring-security                                                                   |                  |
| social-facebook         | Support for spring-social-facebook                                                            |                  |
| social-linkedin         | Support for spring-social-linkedin                                                            |                  |
| social-twitter          | Support for spring-social-twitter                                                             |                  |
| thymeleaf               | Support for the Thymeleaf templating engine, including integration with Spring                |                  |
| vaadin                  | Support for Vaadin                                                                            |                  |
| velocity                | Support for the Velocity templating engine                                                    |                  |
| web                     | Support for full-stack web development, including Tomcat and spring-webmvc                    |                  |
| websocket               | Support for websocket development with Tomcat                                                 |                  |
| ws                      | Support for Spring Web Services                                                               |                  |
+-------------------------+-----------------------------------------------------------------------------------------------+------------------+

From this list, we have already used “web,data-jpa,jms,ws” in our examples. Please also try to use other capabilities or dependencies to develop some examples. We will use other dependencies to explore them in my coming posts.

在此列表中,我们已经在示例中使用了“ web,data-jpa,jms,ws”。 也请尝试使用其他功能或依赖项来开发一些示例。 在接下来的文章中,我们将使用其他依赖项来探索它们。

You can read remaining “ThirdParty Tools” option in my coming post at “Spring Boot Initilizr With ThirdParty Tools“.

您可以在我即将发表的文章“ 使用ThirdParty Tools的Spring Boot Initilizr ”中阅读剩余的“ ThirdParty Tools”选项。

That’s it all about “Spring Boot Initilizr With Spring Boot CLI”.

这就是“带有Spring Boot CLI的Spring Boot Initilizr”的全部内容。

Please drop me a comment if you face any issues or have any suggestions.

如果您遇到任何问题或有任何建议,请给我评论。

翻译自: https://www.journaldev.com/8609/spring-boot-initilizr-with-spring-boot-cli

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值