一、serverspringcloud整體父工程Project創(chuàng)建
? ? ? ? 創(chuàng)建父工程圈暗,Packageing是pom模式
? ? ? ? 主要是定義POM文件,將后續(xù)各個(gè)子模塊公用的jar包等統(tǒng)一提出來(lái)裕膀,類似一個(gè)抽象父類
? ? ? ? ? POM文件:
<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.smilexl.springcloud</groupId>
<artifactId>servicespringcloud</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<junit.version>4.12</junit.version>
<log4j.version>1.2.17</log4j.version>
<lombok.version>1.16.18</lombok.version>
</properties>
<dependencyManagement>
<dependencies>
<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.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.0.2.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.0.4</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.0.31</version>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.0</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<!-- 解決微服務(wù)info內(nèi)容詳細(xì)信息顯示 -->
<build>
<finalName>microservicecloud</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<delimiters>
<delimit>$</delimit>
</delimiters>
</configuration>
</plugin>
</plugins>
</build>
<modules>
<module>servicespringcloud-api</module>
</modules>
</project>
二员串、serverspringcloud-api公共子模塊module
? ??<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>
<!-- 子類里面顯示聲明才能有明確的繼承表現(xiàn),無(wú)意外就是父類的默認(rèn)版本否則自己定義 -->
<parent>
<groupId>com.smilexl.springcloud</groupId>
<artifactId>microservicecloud</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>microservicecloud-api</artifactId><!-- 當(dāng)前Module我自己叫什么名字 -->
<!-- 當(dāng)前Module需要用到的jar包昼扛,按自己需求添加寸齐,如果父類已經(jīng)包含了,可以不用寫(xiě)版本號(hào) -->
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>
新建部門(mén)Entity且配合Lombok使用:
package com.smilexl.springcloude.entities;
import java.io.Serializable;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
@SuppressWarnings("serial") //壓制警告
@NoArgsConstructor? //無(wú)參構(gòu)造方法
@Data? // setter抄谐、getter 方法
@Accessors(chain=true) //鏈?zhǔn)浇Y(jié)構(gòu)
public class Dept implements Serializable{? //必須實(shí)現(xiàn)序列化
private Long id;? ? //主鍵
private String dname;// 部門(mén)名稱
private String db_source; //來(lái)自哪個(gè)數(shù)據(jù)庫(kù)
}
? mvn clean install后給其它模塊引用渺鹦,達(dá)到通用目的。即用到部門(mén)實(shí)體的話蛹含,不用每一個(gè)工程都定義一份毅厚,直接引用模塊即可。
? ??