Note
以更新gihub地址,为了铺垫springcloud,得先清楚springboot多模块项目搭建。
往后更新spark,springcloud,hadoop。
现在SpringBoot越来越流行,其配置少的特点,让我们不论是做传统Web还是微服务都青睐于SpringBoot
这里阐述一下 SpringBoot 多模块用maven搭建+H2测试+maven profile
最近做了简化没有分那么多module
Github
地址:https://github.com/hui-base-springboot/
分支:master
重点
- POM.XML的构建
- 多模块依赖关系
- H2引入及测试
- maven profile 引入根据不同环境打包不同配置
- 生成出来应该是一个JAR包,把依赖的包打进去。可以指定生成jar包的filename
- 关注POM文件里面写的
Core - Code
- 我们要划分好自己需要的模块和职责
- nile-hui-springboot(root)
- nile-hui-springboot-common(通用工具)
- nile-hui-springboot-model(entity+mapper)
- nile-hui-springboot-server(service)
- nile–hui-springboot-rest(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.hui.base</groupId>
<artifactId>hui-base-springboot</artifactId>
<packaging>pom</packaging>
<version>1.0.0-SNAPSHOT</version>
<modules>
<module>hui-base-springboot-model</module>
<module>hui-base-springboot-server</module>
<module>hui-base-springboot-rest</module>
<module>hui-base-springboot-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>com-hui-springboot</artifactId>
<groupId>com.hui.springboot</groupId>
<version>0.1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<description>
common包,通用的工具类等
</description>
<artifactId>hui-springboot-common</artifactId>
<name>hui-springboot-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>hui-springboot</artifactId>
<groupId>com.hui.springboot</groupId>
<version>0.1.0-SNAPSHOT</version>
</parent>
<artifactId>hui-base-springboot-server</artifactId>
<name>hui-base-springboot-server</name>
<version>${project.parent.version}</version>
<packaging>jar</packaging>
<description>
server包,service
</description>
<dependencies>
<dependency>
<groupId>com.base.hui</groupId>
<artifactId>hui-base-springboot-common</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>com.base.hui</groupId>
<artifactId>hui-base-springboot-model</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
</configurationFile>
<!-- 允许移动生成的文件 -->
<verbose>true</verbose>
<!-- 是否覆盖 -->
<overwrite>true</overwrite>
</configuration>
<dependencies>
<!--JDBC postgresql-->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>${postgresql.version}</version>
</dependency>
<!-- mybatis-generator-core -->
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>${mybatis.generator}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
<finalName>hui-base-spring-server</finalName>
</build>
</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">
<parent>
<artifactId>hui-base-springboot</artifactId>
<groupId>com.hui.base</groupId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>hui-base-springboot-rest</artifactId>
<description>Controller/API层</description>
<version>${project.parent.version}</version>
<packaging>jar</packaging>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<description>
controller,也是构建包的POM
</description>
<dependencies>
<!-- models -->
<dependency>
<groupId>com.base.hui</groupId>
<artifactId>hui-base-springboot-server</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>com.base.hui</groupId>
<artifactId>hui-base-springboot-common</artifactId>
<version>${project.parent.version}</version>
</dependency>
<!--spring boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- test -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<!-- Swagger -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
</dependency>
<!-- H2 -->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
<!-- fast json -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
</dependency>
<!-- spring quartz -->
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
</dependency>
</dependencies>
<!-- 根据公司规范 be结尾 并添加版本号 -->
<build>
<finalName>hui-base-springboot-back-${project.parent.version}</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
总结
搭建项目需要跟公司规范挂钩,例如是否有用到NEXUS私有仓库,是否需要源码包,环境的版本等
文章内容并没有困难点,在于自身总结,做一个思考。JAR包版本的选择等。集成一些工具后如何配置好让其生效,并且考虑JAR冲突的因素。
一个宗旨,基础东西,总结! 困难的技术点,总结!困难的使用工具,总结!架构学些,总结!
转载请注明作者感谢~ 自己总结的东西才是自己的