这是我之前的两篇文章的延续。在阅读本文之前,请先阅读我之前在“ Spring Boot Initilizr Web界面 ”和“使用IDE或IDE插件的Spring Boot Initilizr ”中发布的帖子。
Spring Boot Initilizr用于快速启动新的Spring Boot Maven / Gradle项目。它生成初始项目结构并构建脚本以减少开发时间。
正如我在上一篇文章中所讨论的,Spring Boot Initilizr有以下几种形式:
现在我们将讨论如何使用“Spring Boot Initilizr with Spring Boot CLI”选项来引导Spring应用程序。
请先通过这篇文章“Spring Boot CLI Basics”来设置Spring Boot CLI软件。Spring Boot CLI提供了一个“spring init”命令来引导Spring Applications。
我从“https://start.spring.io”下载了Spring Boot CLI zip,并在“D:\ spring-boot-cli-1.2.3.RELEASE”中安装了该软件。
设置以下系统变量:
PATH=D:\spring-boot-cli-1.2.3.RELEASE\bin;%PATH%
“spring init”命令
“spring init”命令是Spring Boot CLI Component中易于使用的命令。它使用“https://start.spring.io”托管的“Spring Initilizr服务”(默认情况下,我们也可以指定目标URL。我们将在下一节讨论这个。)使用Spring引导Spring或Spring Boot应用程序Spring Boot CLI组件。
“spring init”语法
spring init [options] [location]
这里“options”是命令选项,“location”指定我们的文件系统位置以创建新的Spring Boot Project。我们将很快详细讨论命令选项。
使用“spring help init”命令查看所有可用的“spring init”命令选项,如下所示。
spring help init
现在我们将通过一些合适的例子逐一探索“spring init”命令选项。在IDE工作区打开CMD(命令提示符)(我的工作区位于D:\ RamWorkspaces \ SpringSTSBootWorkspace2)并执行以下示例。
示例1: -使用默认设置创建Spring Boot项目:
spring init
它在当前工作目录下使用默认设置创建新的Spring Boot Project zip文件为“demo.zip”。
注意: - “spring init”默认设置:
<dependencies>
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starterartifactId>
dependency>
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-testartifactId>
<scope>testscope>
dependency>
dependencies>
<groupId>org.testgroupId>
<artifactId>demoartifactId>
<version>0.0.1-SNAPSHOTversion>
<packaging>jarpackaging>
<name>demoname>
示例2: -使用所需的依赖项和项目名称创建Spring Boot项目
spring init -d=web,data-jpa,jms,ws SpringMVCMavenToolProject.zip
它使用JPA,JMS和WS功能创建了一个打包的Spring Boot WebApplication。
这里“-d”选项意味着我们可以用逗号分隔值列出所有必需的功能。
“SpringMVCMavenToolProject.zip”是在当前工作目录中使用该名称创建的项目名称和zip文件。
示例3: -使用Gradle Build Tool的所需依赖项和项目名称创建Spring Boot项目。
spring init -d=web,data-jpa,jms,ws --build=gradle -p=war SpringMVCGradleToolProject
它为Gradle构建工具创建了一个解压缩的Spring Boot WebApplication,其中包含JPA,JMS和WS功能。
示例4: -使用Maven Build Tool所需的依赖项和项目名创建Spring Boot项目。
spring init -d=web,jdbc,ws,cloud-aws,h2 --build=maven
--packaging=war SpringMVCMavenToolProject.zip
它为Maven构建工具创建了一个带有JDBC,AWS Cloud和WS功能的打包Spring Boot WebApplication。
示例-5: -使用指定的Spring Boot和Java版本为Maven Build Tool创建具有所需依赖项和项目名称的Spring Boot项目。
默认情况下,“spring init”命令将拾取“系统变量”并采用适当的Spring Boot和Java版本。但是,可以指定Spring Boot和Java Versions。
我的Windows系统配置了Java Version = 1.8和Spring Boot version = 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
它使用Java 1.7和Spring Boot 1.2.5.RELEASE为Maven构建工具创建了一个带有JDBC,AWS Cloud和WS功能的打包Spring Boot WebApplication。
注意: -
当我们执行“spring init”命令时,我们可以观察到以下消息,说它将连接“Spring Boot Initilizr默认服务”。
Using service at https://start.spring.io
同样,我们可以使用其他“spring init”选项来探索它们。例如,“ - force”强制更新已存在的相同项目名称以及更新以避免错误。
注意: -
我们可以提取使用“spring init”命令创建的zip文件,并将这些项目导入我们最喜欢的Spring IDE(例如: - Spring STS Suite),并继续开发我们的项目相关要求。
我们将使用这些Spring Boot项目开发一些应用程序,以增强我即将发布的帖子中的一些功能。
以下部分列出了受支持的构建选项。
+--------+----------------------------------------------------------------------+
| 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 |
+-------------------------------------------------------------------------------+
默认构建参数值为“maven”
以下部分列出了以逗号分隔的“依赖项”列表支持的标识符。
+-------------------------+-----------------------------------------------------------------------------------------------+------------------+
| 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 | |
+-------------------------+-----------------------------------------------------------------------------------------------+------------------+
从这个列表中,我们已经在我们的示例中使用了“web,data-jpa,jms,ws”。还请尝试使用其他功能或依赖项来开发一些示例。我们将在以后的帖子中使用其他依赖项来探索它们。
您可以在我的帖子“ Spring Boot Initilizr With ThirdParty Tools ”中阅读剩余的“ThirdParty Tools”选项。
这就是“使用Spring Boot CLI的Spring Boot Initilizr”。
如果您遇到任何问题或有任何建议,请给我发表评论。
转载来源:https://www.journaldev.com/8609/spring-boot-initilizr-with-spring-boot-cli