Boot Add 使用指南
您可以使用 project list 命令中所有可用的项目,向现有项目添加代码和配置。
CLI 通过以下方式实现:
-
合并 Maven 构建文件,以便将任何缺失的项目属性、依赖项、依赖项管理和插件添加到目标项目。
-
执行包重构,以便将要复制到目标项目中的代码具有相同的包结构。
-
在目标项目的 Spring Boot 主应用程序中添加任何缺失的注解。
-
将
README.adoc(或 .md)文件重命名为README-<project-name>.adoc,以便您可以描述添加的代码的其他信息。 -
合并
application.yaml和application.properties文件。
目前,执行此任务的启发式算法尚未 100% 完成,因此早期使用者可能会遇到一些问题。
例如,假设我们已经添加了入门目录
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