-
先帖下目录结构,直接在idea里面新建就行,删掉多余的文件
-
子模块的新建
-
根目录pom文件,注意modules、packaging,dependencyManagement统一管理依赖,子模块添加依赖的时候就不用加版本号
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.0</version>
<relativePath/>
</parent>
<groupId>com.dashu</groupId>
<artifactId>technology</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>technology</name>
<description>technology</description>
<packaging>pom</packaging>
<properties>
<java.version>17</java.version>
<version>0.0.1-SNAPSHOT</version>
</properties>
<modules>
<module>start</module>
<module>api</module>
<module>service</module>
<module>infrastructure</module>
</modules>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.dashu</groupId>
<artifactId>api</artifactId>
<version>${version}</version>
</dependency>
<dependency>
<groupId>com.dashu</groupId>
<artifactId>infrastructure</artifactId>
<version>${version}</version>
</dependency>
<dependency>
<groupId>com.dashu</groupId>
<artifactId>service</artifactId>
<version>${version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
- start模块pom文件,只放用来启动springboot的依赖和需要暴露的接口模块,注意需要依赖你要提供的api接口模块,就是@RequestMapping、@RestController的那个模块
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.dashu</groupId>
<artifactId>technology</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>start</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>start</name>
<description>start</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.dashu</groupId>
<artifactId>api</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
- 帖一个api的模块的pom,其它模块的基本一样
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.dashu</groupId>
<artifactId>technology</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>api</artifactId>
<name>api</name>
<description>api</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
</dependencies>
</project>
- start启动项需要增加个包扫描@SpringBootApplication(scanBasePackages = {“com.dashu”}),不然访问不了api路径
package com.dashu.start;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication(scanBasePackages = {"com.dashu"})
public class StartApplication {
public static void main(String[] args) {
SpringApplication.run(StartApplication.class, args);
}
}
- 验证一下