使用 Boot Add 的指南
您可以使用 `project list` 命令中所有可用的项目,向现有项目添加代码和配置。
CLI 通过以下方式实现:
-
合并 Maven 构建文件,以便将任何缺失的项目属性、依赖项、依赖管理和插件添加到目标项目中。
-
执行包重构,以便将要复制的代码以相同的包结构复制到目标项目中。
-
在目标项目的 Spring Boot 主应用中添加任何缺失的注解。
-
将 `README.adoc`(或 .md)文件重命名为 `README-<项目名称>.adoc`,以便您可以描述所添加代码的附加信息。
-
合并 `application.yaml` 和 `application.properties` 文件。
目前,执行此任务的启发式算法尚未完全完善,因此如果您是早期使用者,可能会遇到一些问题。
例如,假设我们添加了入门目录
spring catalog add gs https://github.com/rd-1-2022/spring-gs-catalog
这将提供以下项目供您选择
┌──────────┬────────────────────────────────────────────────────────┬────────────────────────────────────────────────────────────────┬───────┬──────────────┐
│Name │URL │Description │Catalog│Tags │
├──────────┼────────────────────────────────────────────────────────┼────────────────────────────────────────────────────────────────┼───────┼──────────────┤
│web │https://github.com/rd-1-2022/rpt-rest-service │Hello, World RESTful web service. │gs │[rest, web] │
├──────────┼────────────────────────────────────────────────────────┼────────────────────────────────────────────────────────────────┼───────┼──────────────┤
│jpa │https://github.com/rd-1-2022/rpt-spring-data-jpa │Learn how to work with JPA data persistence using Spring Data │gs │[jpa, h2] │
│ │ │JPA. │ │ │
├──────────┼────────────────────────────────────────────────────────┼────────────────────────────────────────────────────────────────┼───────┼──────────────┤
│eureka │https://github.com/rd-1-2022/eureka │Spring Cloud Eureka Server │gs │[cloud, │
│ │ │ │ │eureka] │
└──────────┴────────────────────────────────────────────────────────┴────────────────────────────────────────────────────────────────┴───────┴──────────────┘
我们可以创建一个新的 web 项目,然后通过运行以下命令向该项目添加 JPA 功能
spring boot new demo web --package-name com.xkcd
cd demo
spring boot add jpa
项目树现在包含 web 应用和 JPA 功能
$ tree
.
├── LICENSE
├── mvnw
├── mvnw.cmd
├── pom.xml
├── README.adoc
├── README-jpa.md
└── src
├── main
│ └── java
│ └── com
│ └── xkcd
│ ├── Application.java
│ ├── customer
│ │ ├── CustomerCommandLineRunner.java
│ │ ├── Customer.java
│ │ └── CustomerRepository.java
│ └── greeting
│ ├── GreetingController.java
│ └── Greeting.java
└── test
└── java
└── com
└── xkcd
├── customer
│ └── CustomerRepositoryTests.java
└── greeting
└── GreetingControllerTests.java