SpringBoot多服务共享实体类

场景

SpringBoot系统中,经常会有在多个服务中需要用到同样的一些实体类,比如用户、文件上传或工具类,当需求变动而需要修改时,就不得不每个子服务都修改一遍,其缺点一是效率低下,其二是难以保证同步。

解决方案

1.新建一个项目,将其他服务的公共类及共有依赖抽取到该项目;
公共模块结构

<?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>
	<artifactId>fire_module</artifactId>
	<version>1.0.0</version>
	<groupId>com.xakj</groupId>
	<packaging>jar</packaging>
	<name>fire_module</name>
	<description>通用模块</description>
	<dependencies>
		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>servlet-api</artifactId>
			<version>2.5</version>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>org.hibernate</groupId>
			<artifactId>hibernate-validator</artifactId>
			<version>5.4.2.Final</version>
		</dependency>
		<dependency>
			<groupId>io.springfox</groupId>
			<artifactId>springfox-swagger2</artifactId>
			<version>2.5.0</version>
		</dependency>
		<dependency>
			<groupId>net.sf.json-lib</groupId>
			<artifactId>json-lib</artifactId>
			<version>2.4</version>
			<classifier>jdk15</classifier>
		</dependency>
		<dependency>
			<groupId>com.xiaoleilu</groupId>
			<artifactId>hutool-all</artifactId>
			<version>3.0.9</version>
		</dependency>
	</dependencies>
	<build>
		<pluginManagement>
			<plugins>
				<plugin>
					<artifactId>maven-compiler-plugin</artifactId>
					<configuration>
						<source>1.7</source>
						<target>1.7</target>
						<!--<mainClass>com.xakj.app.Application</mainClass> -->
						<encoding>UTF-8</encoding>
						<compilerArguments>
							<verbose />
							<bootclasspath>${java.home}\lib\rt.jar;${java.home}\lib\jce.jar</bootclasspath>
						</compilerArguments>

					</configuration>
				</plugin>
			</plugins>
		</pluginManagement>
	</build>
</project>

2.打包安装到本地仓库;
3.将其他项目的重复代码和依赖删除;
4.引入新项目依赖。

<!-- 共用模块 -->
		<dependency>
			<groupId>com.xakj</groupId>
			<artifactId>fire_module</artifactId>
			<version>1.0.0</version>
		</dependency>
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值