SpringBoot 多模組專案搭建+H2測試+profile
阿新 • • 發佈:2018-12-14
前言
現在SpringBoot越來越流行,其配置少的特點,讓我們不論是做傳統Web還是微服務都青睞於SpringBoot
這裡闡述一下 SpringBoot 多模組用maven搭建+H2測試+maven profile
轉載請註明作者感謝~
重點
- POM.XML的構建
- 多模組依賴關係
- H2引入及測試
- maven profile 引入根據不同環境打包不同配置
- 生成出來應該是一個JAR包,把依賴的包打進去。可以指定生成jar包的filename
- 關注POM檔案裡面寫的
Core - Code
- 我們要劃分好自己需要的模組和職責
- nile-cmszbs-szcst-be(root)
- nile-cmszbs-szcst-common(通用工具)
- nile-cmszbs-szcst-cs (servier+dao+domain)
- nile-cmszbs-szcst-rs(controller)
<?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>com.richstonedt.nile.cmszbs.szcst</groupId>
<artifactId>nile-cmszbs-szcst-be</artifactId>
<packaging>pom</packaging>
<version>0.1.0-SNAPSHOT</version>
<modules>
< module>nile-cmszbs-szcst-rs</module>
<module>nile-cmszbs-szcst-cs</module>
<module>nile-cmszbs-szcst-common</module>
</modules>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
</parent>
<description>
root的pom.xml 其他多個子模組公用的包可以在這裡引入 子模組引用這些JAR包則不需要填寫VERSION
</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<mybatis.spring.boot.starter.version>1.3.0</mybatis.spring.boot.starter.version>
<commons.lang3.version>3.6</commons.lang3.version>
<swagger2.version>2.7.0</swagger2.version>
<mybatis.generator>1.3.7</mybatis.generator>
<postgresql.version>9.4.1212</postgresql.version>
<h2.version>1.4.197</h2.version>
<pagehelper.version>1.2.7</pagehelper.version>
<quartz.version>2.2.3</quartz.version>
<fastjson.version>1.2.39</fastjson.version>
<poi.version>3.17</poi.version>
<logback.version>1.1.11</logback.version>
<druid.version>1.1.10</druid.version>
</properties>
<profiles>
<profile>
<id>dev</id>
<properties>
<!-- 開發環境 -->
<activatedProperties>dev</activatedProperties>
</properties>
<activation>
<!-- 預設環境 -->
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<!-- 測試環境 -->
<id>test</id>
<properties>
<activatedProperties>test</activatedProperties>
</properties>
</profile>
<profile>
<!-- 生產環境 -->
<id>prod</id>
<properties>
<activatedProperties>prod</activatedProperties>
</properties>
</profile>
</profiles>
<!-- 統一依賴管理放root的pom.xml 子模組引用這些JAR包則不需要填寫VERSION-->
<dependencyManagement>
<dependencies>
<!--log -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
</dependency>
<!--mybatis -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>${mybatis.spring.boot.starter.version}</version>
</dependency>
<!--H2-->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>${h2.version}</version>
<scope>test</scope>
</dependency>
<!-- fast json -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>${fastjson.version}</version>
</dependency>
<!--PG SQL-->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>${postgresql.version}</version>
</dependency>
<!--druid連線池-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>${druid.version}</version>
</dependency>
<!-- apache poi -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>${poi.version}</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>${poi.version}</version>
</dependency>
<!-- apache common -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons.lang3.version}</version>
</dependency>
<!-- pagehelper -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>${pagehelper.version}</version>
</dependency>
<!-- Swagger -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${swagger2.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${swagger2.version}</version>
</dependency>
<!-- spring quartz -->
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>${quartz.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<distributionManagement>
<repository>
<id>nexus_production</id>
<url>nexus_production URL</url>
</repository>
<snapshotRepository>
<id>nexus_snapshots</id>
<url>nexus_snapshots URL</url>
</snapshotRepository>
</distributionManagement>
</project>
<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>nile-cmszbs-szcst-be</artifactId>
<groupId>com.richstonedt.nile.cmszbs.szcst</groupId>
<version>0.1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<description>
common包,通用的工具類等
</description>
<artifactId>nile-cmszbs-szcst-common</artifactId>
<name>nile-cmszbs-szcst-common</name>
<version>${project.parent.version}</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<!-- apache poi -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
</dependencies>
</project>
<?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>
<parent>
<artifactId>nile-cmszbs-szcst-be</artifactId>
<groupId>com.richstonedt.nile.cmszbs.szcst</groupId>
<version>0.1.0-SNAPSHOT</version>
</parent>
<artifactId>nile-cmszbs-szcst-cs</artifactId>
<name>nile-cmszbs-szcst-cs</name>
<version>${project.parent.version}</version>
<packaging>jar</packaging>
<description>
CS包,service+dao+domain
</description>
<dependencies>
<dependency>
<groupId>com.richstonedt.nile.cmszbs.szcst</groupId>
<artifactId>nile-cmszbs-szcst-common</artifactId>
<version>${project.parent.version}</version>
</dependency>
<!--spring boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<!--mybatis -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
</dependency>
<!--log -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>
<!--PG SQL-->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<!--H2-->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
<!--druid連線池-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
</dependency>
<!-- pagehelper -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>${mybatis.generator}</version>
<configuration>
<!-- 配置檔案 -->
<configurationFile>
${basedir}/src/main/resources/generator/generatorConfig.xml