前言:该文章只是记录自己平时的点点滴滴.来激励自己成长.长成自己喜欢的人!
环境:
- 电脑 Mac 10.13.1
- IntelliJ IDEA 2018.2 (Ultimate Edition)
- Spring boot 2.0.1.RELEASE
- Maven 项目
实现方案:
- 最高级pom 管理全部jar版本 dependencyManagement -> dependencies 并且添加必须引用的
- 次高级parent -> pom 引入常用jar
- 核心代码core
- 工具代码common
实现细节:
- nmnl-core 引入验证validation @Configuration @Bean 验证 ,core 引入全局异常处理类 @RestControllerAdvice @ExceptionHandler(value = Exception.class)
- nmnl-common内增加异常枚举
- nmnl-demo 实例
1. 最高级pom
<?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.cn.nmnl</groupId>
<artifactId>nmnl</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>nmnl</name>
<modules>
<module>nmnl-parent</module>
<module>nmnl-common</module>
<module>nmnl-core</module>
<module>nmnl-demo</module>
</modules>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.RELEASE</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<!-- bean set / get model -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<!-- 提取公有版本统一管理 START-->
<dependency>
<groupId>com.cn.nmnl</groupId>
<artifactId>nmnl-core</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.cn.nmnl</groupId>
<artifactId>nmnl-common</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<!-- 提取公有版本统一管理 END-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Finchley.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.22</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.2</version>
</dependency>
<!-- 分页插件 -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.5</version>
</dependency>
<!-- alibaba的druid数据库连接池 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.9</version>
</dependency>
<!-- mysql连结 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.46</version>
<scope>runtime</scope>
</dependency>
<!-- 接口文档生产依赖 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.6.1</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.6.1</version>
</dependency>
<!-- elasticsearch 依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</a