创建父级目录
1、创建项目,点击File,创建新的maven工程
![](https://img-blog.csdnimg.cn/img_convert/19e2054a90456626e936235f02656fd1.png)
2、填入编号,项目名称
![](https://img-blog.csdnimg.cn/img_convert/1174fd30446457e52fcb00f89fc6a345.png)
3、在pom.xml文件中,设置打包方式
![](https://img-blog.csdnimg.cn/img_convert/2f338a8f3872c45e1be3b3983d393f05.png)
创建子模块
1、在父级目录下进行子模块的创建
![](https://img-blog.csdnimg.cn/img_convert/a82a796fd82f6c09179ce7fffe8c6245.png)
2、在父级工程下新建一个公共模块common,放置的是一些常用的包之类的,听这个名字都知道common常用。
![](https://img-blog.csdnimg.cn/img_convert/b08ab02f87cbd4571450ba17bf630a95.png)
3、子模块的打包方式
![](https://img-blog.csdnimg.cn/img_convert/221931db0854fdbf510ba9c767e8a2b8.png)
4、如何表示父级项目和子级模块项目的关系,在父级项目中有model表示其下的子模块
![](https://img-blog.csdnimg.cn/img_convert/5e28999acd3381d0b569b7928d289bd4.png)
补充项目之间的关系:
a. 聚合项目中可以分为顶级项目(父级项目)与子工程,父子继承关系,子工程在maven中叫模块,模块之间是平级,可以相互依赖(可以调用对方接口和jar包)
b. 子模块可以使用父级工程中的资源,子模块的之间如果相互使用资源,就必须配置依赖关系
c. 一个顶级工程(父)可以由多个子工程组合
5、然后依次进行创建common、pojo、mapper、service、api模块
其配置如下:common
<artifactId>wxshare-common</artifactId>
pojo
<!--pojo引用common包-->
<dependencies>
<dependency>
<groupId>com.wt</groupId>
<artifactId>wxshare-common</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
mapper
<dependencies>
<dependency>
<groupId>com.wt</groupId>
<artifactId>wxshare-pojo</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
service
<dependencies>
<dependency>
<groupId>com.wt</groupId>
<artifactId>wxshare-mapper</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
api
<dependencies>
<dependency>
<groupId>com.wt</groupId>
<artifactId>wxshare-service</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
6、完善父工程的pom.xml
<!--有的话代表有springboot工程 加载很多依赖-->
<parent>
<artifactId>spring-boot-starter-parent</artifactId>
<groupId>org.springframework.boot</groupId>
<version>2.1.5.RELEASE</version>
<!--设置查找属性 当前地址-本地仓库-远程仓库-->
<relativePath />
</parent>
<!--设置资源属性-->
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<!--排除springboot默认的日志依赖 后期自己整合-->
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<!--配置spring项目的web板块-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--配置解析xml-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
完整的项目模块
![](https://img-blog.csdnimg.cn/img_convert/dcd780bd0483c8bf09e34147e4bf1722.png)
测试模块
1、api模块中,创建application.properties(resource包)
2、在java中创建com.wt包,创建启动类Application.java
//启动类09
@SpringBootApplication //扫描所有包
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class);
}
}
3、创建controller测试类,com.wt.controller.TestController.java
@RestController
public class TestController {
//指定接收一个get请求
@GetMapping("/test")
public Object test() {
return "success";
}
}
4、启动Application.java类,直接点击运行application运行即可
![](https://img-blog.csdnimg.cn/img_convert/526a43a9daf75b6f97924f46d487eaf8.png)
5、访问
![](https://img-blog.csdnimg.cn/img_convert/2cbce28a769901e88b3ce0666f40a2d2.png)
常见的问题
1、包没有引入,出现什么缺少插件plugin
这种是因为我们下载的东西和仓库内的冲突了,需要清理仓库,这是一个.bat文件,可以直接运行清理。清理成功以后就需要重新回到软件,刷新一下maven项目,install一下项目。
set REPOSITORY_PATH=C:\Java\maven-repository
rem 正在搜索...
for /f "delims=" %%i in ('dir /b /s "%REPOSITORY_PATH%\*lastUpdated*"') do (
del /s /q %%i
)
rem 搜索完毕
pause
![](https://img-blog.csdnimg.cn/img_convert/95c975aa53464f2a8576e7a71ddeac93.png)
2、运行的程序找不到项目空间
![](https://img-blog.csdnimg.cn/img_convert/e5b27def4660daaef360cd10171d93d4.png)
![](https://img-blog.csdnimg.cn/img_convert/f9cade8da5336f27d63f268db8555346.png)
3、8080端口占用,导致程序不能运行,查找进程杀死进程:netstat -ano
杀死进程:在任务管理器中,性能中资源监视器,找到对应的pid进行手动杀死。
命令杀死:taskkill -pid 2086(pid号) -f ,f是强制杀死。