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具有以下形式:
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应用程序。
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
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”默认设置:
org.springframework.boot
spring-boot-starter
org.springframework.boot
spring-boot-starter-test
test
org.test
demo
0.0.1-SNAPSHOT
jar
demo
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。
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。
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。
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