本文介绍了Maven 搭建spring boot多模块项目,分享给大家,具体如下:
备注:所有项目都在idea中创建
1.idea创建maven项目
- 1-1: 删除src,target目录,只保留pom.xml
- 1-2: 根目录pom.xml可被子模块继承,因此项目只是demo,未考虑太多性能问题,所以将诸多依赖。都写在根级`pom.xml`,子模块只需继承就可以使用。
- 1-3: 根级pom.xml文件在附录1
- 1-4: 依赖模块 mybatis spring-boot相关模块
2.创建子模块(module)
- 2-1: file > new > module 输入 model
- 2-2: file > new > module 输入 dao
- 2-3: file > new > module 输入 service
- 2-4: file > new > module 输入 webapi
3.修改子模块pom.xml配置
<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://.luyh.projectv1</groupId> <artifactId>parent</artifactId> <version>1.0-SNAPSHOT</version> <packaging>pom</packaging> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.3.3.RELEASE</version> </parent> <modules> <module>model</module> <module>dao</module> <module>service</module> <module>webapi</module> </modules> <!--申明依赖关系--> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> <version>1.2.2</version> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>3.2.8</version> </dependency> <dependency> <groupId>org.apache.tomcat</groupId> <artifactId>tomcat-jdbc</artifactId> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> </dependencies> <!--设置maven仓库--> <repositories> <repository> <id>spring-releases</id> <url>https://repo.spring.io/libs-release</url> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>spring-releases</id> <url>https://repo.spring.io/libs-release</url> </pluginRepository> </pluginRepositories></project>
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。