1. Create the parent project
Open IntelliJ IDEA and selectNew Project。
Select in the Create WizardMaven, make sure to selectCreate from archetype,choose:maven-archetype-quickstart。
-
Fill in project information:
GroupId:
(Can be modified according to requirements)
ArtifactId:
springboot-aggregator
(The name of the parent project)Version:
1.0-SNAPSHOT
(or other version number)
ClickFinishComplete the creation of the parent project.
2. Configure the parent project's
In parent projectIn the file, add Spring Boot's parent POM and other related configurations to manage all submodules:
<project xmlns="/POM/4.0.0" xmlns:xsi="http:///2001/XMLSchema-instance" xsi:schemaLocation="/POM/4.0.0 /xsd/maven-4.0."> <modelVersion>4.0.0</modelVersion> <groupId></groupId> <artifactId>springboot-aggregator</artifactId> <version>1.0-SNAPSHOT</version> <packaging>pom</packaging> <parent> <groupId></groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.7.5</version> <relativePath/> </parent> <modules> <!-- Submodules will be listed here --> </modules> <properties> <>1.8</> </properties> <dependencyManagement> <dependencies> <!-- Unified management dependency version --> <dependency> <groupId></groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> </dependencyManagement> </project>
3. Create submodules
Right-click the parent project (
springboot-aggregator
),chooseNew > Module。chooseMavenModule type, then fill in the module name (for example
service-user
,service-product
,service-order
)。After the module is created, in the parent project
The corresponding submodules will be automatically added to the file
<module>
。
4. Configure the submodule
Each submodule'sInherit the parent module and add relevant dependencies as needed. For example,
service-user
ModularIt can be as follows:
<project xmlns="/POM/4.0.0" xmlns:xsi="http:///2001/XMLSchema-instance" xsi:schemaLocation="/POM/4.0.0 /xsd/maven-4.0."> <modelVersion>4.0.0</modelVersion> <groupId></groupId> <artifactId>service-user</artifactId> <version>1.0-SNAPSHOT</version> <packaging>jar</packaging> <parent> <groupId></groupId> <artifactId>springboot-aggregator</artifactId> <version>1.0-SNAPSHOT</version> <relativePath>../</relativePath> </parent> <dependencies> <dependency> <groupId></groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId></groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
5. Write Spring Boot application code
Write specific business logic in each submodule. For example,service-user
In the module, create a simple Spring Boot application:
package ; import ; import ; @SpringBootApplication public class ServiceUserApplication { public static void main(String[] args) { (, args); } }
6. Build and run
Execute in the parent project
mvn clean install
To build the entire aggregation project.At runtime, Spring Boot application can be run separately in each submodule. For example,
service-user
Right-click in the module,chooseRunTo start the Spring Boot application of this module.
Through the above steps, you can successfully build a Spring Boot aggregation project to help you better manage different functional modules.
This is the end of this article about the implementation example of building Spring Boot aggregation projects. For more information about building Spring Boot aggregation projects, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!