# SpringBoot3教程 - 21 多模块SpringBoot项目
前面在使用 IDEA 创建SpringBoot项目的时候,是一个单模块应用。
就像下面的项目,只有一个 hello-springboot
模块。
在实际的开发中,由于系统功能复杂,代码越来越多,写在一个模块中会非常臃肿,项目的结构也非常不清晰。所以为了项目结构清晰,易于管理,我们可以根据不同的规则将项目划分为多个模块。
例如根据不同的业务功能,商品管理、订单管理、用户管理等拆分成不同的子模块。根据不同的组件划分,例如消息队列、定时任务等拆分成不同的子模块。或根据不同的层次划分,将控制层、服务处、数据访问层划分成不同的子模块,这些都可以,根据自己的需求进行不同的划分。
下面演示一下创建三个模块的 SpringBoot 项目:
- doubi-dao,用于放实体类和mybatis-plus的mapper
- doubi-service,用于放service
- doubi-api,用于放controller
这里只是演示一下如何创建多个模块,具体如何划分项目,根据自己的需求。
最终的项目结构:
在创建的过程中,遇到依赖的问题,可以手动Reload一下maven,遇到找不到子模块,保证依赖没有问题的情况下install一下子模块。
开整!
# 21.1 创建Maven父项目
# 1 创建父项目
首先创建一个Maven项目作为父项目,后面在这个项目下面创建多个子模块。
然后删除项目中的src,不需要:
# 2 父项目添加依赖
在父项目的 pom.xml 中添加依赖。
为了保持模块间依赖统一,在父模块中使用 dependencyManagement
预定义所有模块需要用到的依赖和版本,如果父项目和子模块需要用到依赖,引入依赖的时候不需要指定版本。
注意: dependencyManagement
中的依赖不是真的引入,这是约束,引入需要在 <dependencies>
中添加。
搭建 SpringBoot 项目除了像之前那样继承 spring-boot-starter-parent
,还可以使用 spring-boot-dependencies
。
最终内容如下:
注意,父项目的 <packaging>
为pom类型。
<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.doubi</groupId>
<artifactId>doubi-server</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>doubi-server</name>
<url>http://maven.apache.org</url>
<properties>
<java.version>17</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
<dependencyManagement>
<dependencies>
<!-- SpringBoot的依赖配置-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>3.3.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- mysql依赖 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.28</version>
</dependency>
<!-- mybatis-plus依赖 -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-spring-boot3-starter</artifactId>
<version>3.5.7</version>
</dependency>
<!-- hutool工具包 -->
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.8.25</version>
</dependency>
</dependencies>
</dependencyManagement>
<!-- 这里面是真正引入依赖,这里引入的依赖所有的子模块都可以使用 -->
<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>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
</plugins>
</build>
</project>
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
编辑完成,右键 -> Maven -> Reload project 。
# 21.2 新建Dao层的子模块
创建子模块的时候,可以使用 Spring Initializr
创建,这里为了清晰,我时候用 Maven 项目手动来创建。
# 1 创建子模块
创建一个 Maven 项目的子模块 doubi-dao
:
创建后,删除自动创建的类、测试类。
# 2 添加依赖
然后在当前子模块的 pom.xml 中添加相关依赖:
- 因为 Dao 层要操作数据库, 所以添加 mybatis-plus 依赖
- 给模块添加一下版本号
<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>doubi-server</artifactId>
<groupId>com.doubi</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>doubi-dao</artifactId>
<packaging>jar</packaging>
<!-- 添加版本号 -->
<version>0.0.1-SNAPSHOT</version>
<name>doubi-dao</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- mysql驱动依赖 -->
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
</dependency>
<!-- mybatis-plus依赖 -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-spring-boot3-starter</artifactId>
</dependency>
</dependencies>
</project>
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
编辑完成,右键 -> Maven -> Reload project 。
# 3 在父项目中添加子项目依赖
在创建子项目的时候,父项目的 pom.xml 会生成子项目的模块:
<modules>
<module>doubi-dao</module>
</modules>
2
3
在父项目的 <dependencyManagement>
模块中添加 Dao 子项目模块:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.doubi</groupId>
<artifactId>doubi-dao</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
</dependencyManagement>
2
3
4
5
6
7
8
9
10
11
这样后面其他的模块可以依赖该模块。
添加完成,父项目右键 -> Maven -> Reload project 。
# 4 创建实体类
创建包,然后创建类User.java
package com.doubi.dao.pojo;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.util.Date;
@Data
@TableName("tb_user")
public class User {
@TableId
private String id;
private String username;
private Integer age;
private Date createTime;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 5 创建Mapper
创建包,然后创建mapper,继承BaseMapper。
package com.doubi.dao.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.doubi.dao.pojo.User;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface UserMapper extends BaseMapper<User> {
}
2
3
4
5
6
7
8
9
# 6 编写MybatisPlus配置类
编写MybatisPlus的配置类。主要指定扫描Mapper的路径。后面MybatisPlu有其他配置,可以配置到这个配置类中。
package com.doubi.dao.config;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Configuration;
@Configuration
@MapperScan({"com.doubi.dao.**.mapper"})
public class MyBatisPlusConfig {
}
2
3
4
5
6
7
8
9
10
# 21.3 新建Service层的子模块
# 1 创建子模块
和上面创建Dao层的子模块是一样的,名称不一样而已,为 doubi-service
。
将模块中生成的多余的类、测试类删除。
# 2 添加依赖
因为service模块要调用dao模块,所以在当前子模块中添加dao模块的依赖。给当前模块添加一个version
,后面接口模块引用的时候需要。
<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>doubi-server</artifactId>
<groupId>com.doubi</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<version>0.0.1-SNAPSHOT</version>
<artifactId>doubi-service</artifactId>
<packaging>jar</packaging>
<name>doubi-service</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- 依赖dao子模块 -->
<dependency>
<groupId>com.doubi</groupId>
<artifactId>doubi-dao</artifactId>
</dependency>
</dependencies>
</project>
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# 3 在父项目中添加子项目依赖
在父项目的pom.xml文件中添加子项目的依赖。
在创建子项目的时候,父项目的 pom.xml 会生成子项目的模块:
<modules>
<module>doubi-dao</module>
<module>doubi-service</module>
</modules>
2
3
4
在父项目的 <dependencyManagement>
模块中添加 Dao 子项目模块:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.doubi</groupId>
<artifactId>doubi-service</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
</dependencyManagement>
2
3
4
5
6
7
8
9
10
11
这样后面其他的模块可以依赖该模块。
添加完成,父项目右键 -> Maven -> Reload project 。
# 4 创建service
创建 service,调用dao模块的mapper。
UserServiceImpl.java
package com.doubi.service.service.impl;
import com.doubi.dao.mapper.UserMapper;
import com.doubi.dao.pojo.User;
import com.doubi.service.service.IUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
@Slf4j
@Service
public class UserServiceImpl implements IUserService {
@Autowired
private UserMapper userMapper;
/**
* 通过ID查找用户
*/
public User getUserById(String userId) {
log.info("根据ID查找用户, userId:{}", userId);
User user = userMapper.selectById(userId);
return user;
}
/**
* 保存用户
*/
public User saveUser(String username, Integer age) {
User user = new User();
user.setUsername(username);
user.setAge(age);
user.setCreateTime(new Date());
userMapper.insert(user);
return user;
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
接口IUserService.java
package com.doubi.service.service;
import com.doubi.dao.pojo.User;
public interface IUserService {
/**
* 通过ID查找用户
*/
User getUserById(String userId);
/**
* 保存用户
*/
User saveUser(String username, Integer age);
}
2
3
4
5
6
7
8
9
10
11
12
13
14
# 21.4 新建接口层的子模块
# 1 创建子模块
和前面创建子模块一样。名称为 doubi-api
。
将模块中生成的多余的类、测试类删除。
# 2 添加依赖
因为api模块要调用service模块,所以在当前子模块中添加service模块的依赖,dao模块通过service模块依赖传递,这里就不用引入了。
给当前模块添加一个
version
。添加用于打包的插件。
<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>doubi-server</artifactId>
<groupId>com.doubi</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>doubi-api</artifactId>
<packaging>jar</packaging>
<!-- 添加版本号 -->
<version>0.0.1-SNAPSHOT</version>
<name>doubi-api</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- 需要依赖doubi-service -->
<dependency>
<groupId>com.doubi</groupId>
<artifactId>doubi-service</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<!-- 用于打包 -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal><!--可以把依赖的包都打包到生成的Jar包中-->
</goals>
</execution>
</executions>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# 3 在父项目中添加子项目依赖
在父项目的pom.xml文件中添加子项目的依赖。
在创建子项目的时候,父项目的 pom.xml 会生成子项目的模块:
<modules>
<module>doubi-dao</module>
<module>doubi-service</module>
<module>doubi-api</module>
</modules>
2
3
4
5
在父项目的 <dependencyManagement>
模块中添加 Dao 子项目模块:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.doubi</groupId>
<artifactId>doubi-api</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
</dependencyManagement>
2
3
4
5
6
7
8
9
10
11
添加完成,父项目右键 -> Maven -> Reload project 。
# 4 创建主启动类
因为该模块是接口层,主启动类放在该模块。
因为主启动类是在 com.doubi.api
包下,而各个模块的各个类是在 com.doubi
包下, 所以使用 @ComponentScan
注解指定 basePackages
。
package com.doubi.api;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication
@ComponentScan(basePackages = {"com.doubi"})
public class DoubiServerApplication {
public static void main(String[] args) {
SpringApplication.run(DoubiServerApplication.class, args);
}
}
2
3
4
5
6
7
8
9
10
11
12
13
# 4 创建controller
定义一个获取和保存数据的接口。
UserController.java
package com.doubi.api.controller;
import com.doubi.dao.pojo.User;
import com.doubi.service.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/user")
public class UserController {
@Autowired
private IUserService userService;
/**
* 获取用户信息
*/
@GetMapping("/{userId}")
public User getById(@PathVariable("userId") String userId) {
return userService.getUserById(userId);
}
/**
* 添加用户
*/
@GetMapping("/add") // 为了方便用get请求
public User saveUser(@RequestParam("username") String username, @RequestParam("age") Integer age) {
return userService.saveUser(username, age);
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# 5 编写配置文件
在 src/main/
目录下创建 resources
文件夹,然后右键 resources
--> Make Directory as
--> Resources Root
,将 resources
设置为资源目录,然后在 resources
目录下创建 application.properties
或者 application.yaml
。
在application.yaml中配置如下:
server:
port: 8080
# 数据源配置
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver # mysql8版本以下com.mysql.jdbc.Driver
password: 123456
username: root
url: jdbc:mysql://localhost:3306/doubi_db?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=GMT
# mybaits-plus配置
mybatis-plus:
# MyBatis Mapper所对应的XML文件位置,这里暂时没用到
mapper-locations: classpath*:/mapper/*Mapper.xml
global-config:
# 关闭MP3.0自带的banner
banner: false
db-config:
# 主键类型 0:数据库ID自增 1.未定义 2.用户输入 3 id_worker 4.uuid 5.id_worker字符串表示
id-type: assign_uuid
#字段策略 0:"忽略判断",1:"非 NULL 判断"),2:"非空判断"
field-strategy: NOT_NULL
# 默认数据库表下划线命名
table-underline: true
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
主要是数据源和mybatis-plus的配置。
# 21.5 测试
请求接口添加数据:http://localhost:8080/user/add?username=doubi&age=13
请求接口获取数据:http://localhost:8080/user/b29907c655bb67f3c10e7d80958b9dbf
# 21.6 最终各个pom.xml
# 1 父项目pom.xml
<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.doubi</groupId>
<artifactId>doubi-server</artifactId>
<version>1.0-SNAPSHOT</version>
<modules>
<module>doubi-dao</module>
<module>doubi-service</module>
<module>doubi-api</module>
</modules>
<packaging>pom</packaging>
<name>doubi-server</name>
<url>http://maven.apache.org</url>
<properties>
<java.version>17</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<spring-boot.version>3.3.0</spring-boot.version>
</properties>
<dependencyManagement>
<dependencies>
<!-- SpringBoot的依赖配置-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- mysql驱动依赖 -->
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<version>8.4.0</version>
</dependency>
<!-- mybatis-plus依赖 -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-spring-boot3-starter</artifactId>
<version>3.5.7</version>
</dependency>
<!-- hutool工具包 -->
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.8.25</version>
</dependency>
<dependency>
<groupId>com.doubi</groupId>
<artifactId>doubi-dao</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.doubi</groupId>
<artifactId>doubi-service</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.doubi</groupId>
<artifactId>doubi-api</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
</dependencyManagement>
<!-- 这里面是真正引入依赖,这里引入的依赖所有的子模块都可以使用 -->
<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>
<!-- spring-boot-dependencies中已经规定了lombok的版本 -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<!-- hutool工具包 -->
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
</plugins>
</build>
</project>
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# 2 dao子模块pom.xml
<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>doubi-server</artifactId>
<groupId>com.doubi</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>doubi-dao</artifactId>
<packaging>jar</packaging>
<!-- 添加版本号 -->
<version>0.0.1-SNAPSHOT</version>
<name>doubi-dao</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- mysql驱动依赖 -->
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
</dependency>
<!-- mybatis-plus依赖 -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-spring-boot3-starter</artifactId>
</dependency>
</dependencies>
</project>
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# 3 service子模块pom.xml
<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>doubi-server</artifactId>
<groupId>com.doubi</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>doubi-service</artifactId>
<packaging>jar</packaging>
<!-- 添加版本号 -->
<version>0.0.1-SNAPSHOT</version>
<name>doubi-service</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- 需要依赖doubi-dao -->
<dependency>
<groupId>com.doubi</groupId>
<artifactId>doubi-dao</artifactId>
</dependency>
</dependencies>
</project>
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# 4 接口子模块pom.xml
<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>doubi-server</artifactId>
<groupId>com.doubi</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>doubi-api</artifactId>
<packaging>jar</packaging>
<!-- 添加版本号 -->
<version>0.0.1-SNAPSHOT</version>
<name>doubi-api</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- 需要依赖doubi-service -->
<dependency>
<groupId>com.doubi</groupId>
<artifactId>doubi-service</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<!-- 用于打包 -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal><!--可以把依赖的包都打包到生成的Jar包中-->
</goals>
</execution>
</executions>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53