根据Spring Boot 3多模块项目架构,以下是一个简化的代码示例:
-- parent-module
|-- pom.xml
|-- src
|-- main
|-- java
|-- resources
|-- test
|-- java
|-- resources
|-- pom.xml
|-- service-module
|-- pom.xml
|-- web-module
|-- pom.xml
parent-module/pom.xml:
```xml
<project ...>
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>parent-module</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<java.version>17</java.version>
<spring-boot.version>3.0.0</spring-boot.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<!-- 其他共用依赖 -->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<modules>
<module>service-module</module>
<module>web-module</module>
</modules>
</project>
service-module/pom.xml:
<project ...>
<parent>
<groupId>com.example</groupId>
<artifactId>parent-module</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>service-module</artifactId>
<dependencies>
<!-- 依赖父POM中定义的共用依赖 -->
<!-- 添加特有服务层依赖 -->
</dependencies>
</project>
web-module/pom.xml:
<project ...>
<parent>
<groupId>com.example</groupId>
<artifactId>parent-module</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>web-module</artifactId>
<dependencies>
<!-- 依赖父POM中定义的共用依赖 -->
<!-- 添加特有Web层依赖 -->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>