Maven项目微服务工程构建
源代码地址:https://gitee.com/hs-sunrui/maven_study_micro.git
一、创建工程
1.创建工程
工程名 | 地位 | 说明 |
---|---|---|
demo-maven-ms | 父工程 | 总体管理各个子工程 |
demo01-gateway | 子工程 | 网关 |
demo02-user-auth-center | 子工程 | 用户中心 |
demo03-emp-manager-center | 子工程 | 员工数据维护中心 |
demo04-memorials-manager-center | 子工程 | 奏折数据维护中心 |
demo05-work-manager-center | 子工程 | 批阅奏折工作中心 |
demo06-mysql-data-provider | 子工程 | mysql数据提供者 |
demo07-redis-data-provider | 子工程 | Redis数据提供者 |
demo08-base-api | 子工程 | 声明feign接口 |
demo09-base-entity | 子工程 | 实体类 |
demo-base-util | 子工程 | 工具类 |
2.建立工程间依赖关系
二、父工程管理依赖
<?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.sr.maven</groupId>
<artifactId>demo-maven-ms</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
<module>demo01-gateway</module>
<module>demo02-user-auth-center</module>
<module>demo03-emp-manager-center</module>
<module>demo04-memorials-manager-center</module>
<module>demo05-work-manager-center</module>
<module>demo06-mysql-data-provider</module>
<module>demo07-redis-data-provider</module>
<module>demo08-base-api</module>
<module>demo09-base-entity</module>
<module>demo-base-util</module>
</modules>
<dependencyManagement>
<dependencies>
<!--springcloud依赖导入-->
<!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-dependencies -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Hoxton.SR9</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!--springcloud Alibab依赖导入-->
<!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-dependencies -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>2.2.6.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!--springboot依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.3.6.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!--通用mapper依赖-->
<!-- https://mvnrepository.com/artifact/tk.mybatis/mapper-spring-boot-starter -->
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper-spring-boot-starter</artifactId>
<version>2.1.5</version>
</dependency>
<!--druid数据源-->
<!-- https://mvnrepository.com/artifact/com.alibaba/druid-spring-boot-starter -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.10</version>
</dependency>
<!--JPA依赖-->
<!-- https://mvnrepository.com/artifact/javax.persistence/persistence-api -->
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
三、打基础
1.demo10-base-util
把前面工程的工具类和异常类拷贝过来
package com.sr.maven.exception;
public class LoginFailException extends RuntimeException{
public LoginFailException() {
super();
}
public LoginFailException(String message) {
super(message);
}
public LoginFailException(String message, Throwable cause) {
super(message, cause);
}
public LoginFailException(Throwable cause) {
super(cause);
}
protected LoginFailException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
}
package com.sr.maven.util;
public class ImperialCourtConst {
public static final String LOGIN_FAIL_MESSAGE = "帐号、密码错误,不可进宫!";
public static final String ACCESS_DENIED_MESSAGE = "宫闱禁地,不可擅入!";
public static final String LOGIN_EMP_ATTR_NAME = "loginInfo";
}