话不多说,直接开始!!!
①先建立父模块model:
然后把src,.idea删除:
右击项目,如图:
②建立子项目model1:
③像步骤二一样依次建立好model2,model3,如图:
④把test删除,把java,resources目录依次设置为Sources root,Ressoures roo:
如图:
⑤如果你想在model2里面在设置子模块,如图设置:
⑥在这个工程里面我们只取model1和model-biz的resources,把其他resoures和test全部删除:
model1下面建立如下模块:
model2-api如下:
model-biz如下:
model3如下:
⑦文件配置:
MSPApplication.class:
package com.fzf.msp;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* @author fanZhiFei
* @create 2022/7/10
*/
@SpringBootApplication
public class MSPApplication {
public static void main(String[] args) {
SpringApplication.run(MSPApplication.class,args);
}
}
application.yml:
spring:
application:
name: model
mybatis-plus:
#xml文件位置
mapper-locations: classpath*:/mapper/*Mapper.xml
server:
port: 8889
model1的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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>model</artifactId>
<groupId>com.fzf</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>model1</artifactId>
<dependencies>
<!--starter-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>2.6.7</version>
</dependency>
<!--进行web开发-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.6.7</version>
</dependency>
</dependencies>
</project>
model2-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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>model2</artifactId>
<groupId>com.fzf</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>model2-api</artifactId>
</project>
model-biz的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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>model2</artifactId>
<groupId>com.fzf</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>model2-biz</artifactId>
</project>
model2的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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>model</artifactId>
<groupId>com.fzf</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>model2</artifactId>
<packaging>pom</packaging>
<modules>
<module>model2-api</module>
<module>model2-biz</module>
</modules>
</project>
model3的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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>model</artifactId>
<groupId>com.fzf</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>model3</artifactId>
</project>
model的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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.fzf</groupId>
<artifactId>model</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
<module>model1</module>
<module>model2</module>
<module>model3</module>
</modules>
<!-- parent指明继承关系,给出被继承的父项目的具体信息-->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
</project>
ok,整个项目大功告成,可以愉快的编写分离的模块的业务代码了:
注意:过程中,可能会遇到Error:java: JDK isn’t specified for module ‘model1’
解决办法:
①
②,选第一个:
③重启之后,右击maven会出现下面这个,当你的pom不是蓝色而是红色的时候,下面会出现add as maven project,选择即可,每一个pom模块都这样操作:
工程例子:
版权声明:本文为qq_45915803原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。