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>