Guide to Using Boot Add

You can use all the projects that are available in the project list command to add code and configuration to an existing project.spring-doc.cn

The CLI does this by:spring-doc.cn

  • Merging the Maven build file, so that any missing project properties, dependencies, dependency management, and plug-ins are added into the target project.spring-doc.cn

  • Performing a package refactoring so that the code to be copied into the target project with the same package structure.spring-doc.cn

  • Adding any missing annotations on the Spring Boot main application in the target project.spring-doc.cn

  • Renaming the README.adoc (or .md) file to README-<project-name>.adoc so that you can describe additional information about what code was added.spring-doc.cn

  • Merging application.yaml and application.properties files.spring-doc.cn

The heuristic to perform this task is not 100% complete at this time, so expect a few bumps if you are an early adopter.spring-doc.cn

For example, assume we have added the getting started catalog:spring-doc.cn

spring catalog add gs https://github.com/rd-1-2022/spring-gs-catalog

This gives us the following projects from which to select:spring-doc.cn

┌──────────┬────────────────────────────────────────────────────────┬────────────────────────────────────────────────────────────────┬───────┬──────────────┐
│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]       │
└──────────┴────────────────────────────────────────────────────────┴────────────────────────────────────────────────────────────────┴───────┴──────────────┘

We can create a new web project and then add JPA functionality to that project by running the following commands:spring-doc.cn

spring boot new demo web --package-name com.xkcd
cd demo
spring boot add jpa

The project tree now contains both the web application and the JPA functionality:spring-doc.cn

$ 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

Conventions

To perform an intelligent merge of the code base when you run spring boot add, the following conventions in the project must be followed:spring-doc.cn

  • You should place the main @SpringBootApplication at the root of the package hierarchy with all other code in subpackages.spring-doc.cn

  • There should be no additional @Bean annotations in the @SpringBootApplication class. Any configuration should live in a separate @Configuration class.spring-doc.cn

Limitations

Currently, only single-module Maven projects are supported. Support for single-module Gradle projects is planned for the 1.0 release. No timeline is defined for supporting multi-module projects.spring-doc.cn