SpringBoot 能够快速建立 Web 应用,在平时工做中通常由多我的分工合做,此时使用 SpringBoot 多模块再合适不过了,多模块经过 Maven 的父子依赖实现分工和聚合。
多模块项目打包不能使用spring-boot-maven-plugin 构建插件,应该给终端项目使用,由于这个插件的 repackage 目标会处理 jar 包,致使依赖它的模块没法使用它。在 parent 项目中使用它会致使每一个子项目都执行了该目标,进而出现编译失败。java
项目github地址: https://github.com/AaronSheng/SpringBoot-Modules
SpringBoot 多模块项目建立过程:mysql
<?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>SpringBoot-Modules</groupId> <artifactId>SpringBoot-Modules</artifactId> <packaging>pom</packaging> <version>1.0-SNAPSHOT</version> <modules> <module>util</module> <module>dao</module> <module>config</module> <module>domain</module> <module>service</module> <module>web</module> </modules> <properties> <java.version>1.8</java.version> </properties> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.4.3.RELEASE</version> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-logging</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-log4j2</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-orm</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-aop</artifactId> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> <!-- hibernate--> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-entitymanager</artifactId> <version>4.3.6.Final</version> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> <version>4.3.6.Final</version> </dependency> <!-- druid + mysql --> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>1.0.13</version> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.7</version> </dependency> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-web</artifactId> <version>2.6.2</version> </dependency> </dependencies> <profiles> <profile> <id>dev</id> <activation> <activeByDefault>true</activeByDefault> </activation> <build> <resources> <resource> <directory>web/src/main/resources/dev</directory> </resource> <resource> <directory>src/main/resources</directory> </resource> </resources> </build> </profile> <profile> <id>test</id> <build> <resources> <resource> <directory>web/src/main/resources/test</directory> </resource> <resource> <directory>src/main/resources</directory> </resource> </resources> </build> </profile> <profile> <id>pro</id> <build> <resources> <resource> <directory>web/src/main/resources/pro</directory> </resource> <resource> <directory>src/main/resources</directory> </resource> </resources> </build> </profile> </profiles> </project>