搭建简单的SpringCloud项目一:注册中心和公共层
2021-06-04 00:02
标签:app reg ruid exp work width depend public registry 注:笔者在搭建途中其实遇见不少问题,统一放在后面的文章说明,现在的搭建是测试OK的。 GitHub:https://github.com/ownzyuan/test-cloud 创建一个非常简单的user表 新建Maven项目(不直接创建SpringBoot项目): 删掉父工程的src,引入SprinCloud、SprinBoot、Eureka、tkMybatis、Lombok等的依赖 新建Moudle eureka项目中pom依赖: application文件配置 最后创建启动类,注意加入@EnableEurekaServer 启动项目并访问http://localhost:8081/ 注册中心完成 注:非必要加入的一层,仅为了方便统一管理。 这一层主要是将一些基础功能做好封装,在需要的时候直接继承过去就行。 引入Lombok、tkMybatis 首先是基础DTO对象 然后是IBaseService接口 对应实现类(注意有些方法不实现,故使用抽象类): 依赖与common-base一样,同时将common-base层也引进来 创建User实体 创建UserDTO: 搭建简单的SpringCloud项目一:注册中心和公共层 标签:app reg ruid exp work width depend public registry 原文地址:https://www.cnblogs.com/kzyuan/p/14666140.html数据库
父工程
dependencyManagement>
dependencies>
?
dependency>
groupId>org.springframework.cloudgroupId>
artifactId>spring-cloud-dependenciesartifactId>
version>Greenwich.SR1version>
type>pomtype>
scope>importscope>
dependency>
?
dependency>
groupId>org.springframework.bootgroupId>
artifactId>spring-boot-dependenciesartifactId>
version>2.1.4.RELEASEversion>
type>pomtype>
scope>importscope>
dependency>
?
dependency>
groupId>org.springframework.cloudgroupId>
artifactId>spring-cloud-starter-eureka-serverartifactId>
version>1.4.0.RELEASEversion>
dependency>
?
dependency>
groupId>org.springframework.cloudgroupId>
artifactId>spring-cloud-starter-eurekaartifactId>
version>1.4.0.RELEASEversion>
dependency>
?
dependency>
groupId>org.springframework.cloudgroupId>
artifactId>spring-cloud-openfeign-coreartifactId>
version>2.0.1.RELEASEversion>
dependency>
?
dependency>
groupId>org.springframework.cloudgroupId>
artifactId>spring-cloud-starter-openfeignartifactId>
version>2.0.1.RELEASEversion>
dependency>
?
dependency>
groupId>mysqlgroupId>
artifactId>mysql-connector-javaartifactId>
version>5.1.47version>
dependency>
?
dependency>
groupId>com.github.drtranggroupId>
artifactId>druid-spring-boot2-starterartifactId>
version>1.1.10version>
dependency>
?
dependency>
groupId>tk.mybatisgroupId>
artifactId>mapper-spring-boot-starterartifactId>
version>1.1.2version>
dependency>
?
dependency>
groupId>tk.mybatisgroupId>
artifactId>mapperartifactId>
version>3.4.1version>
dependency>
?
dependency>
groupId>org.projectlombokgroupId>
artifactId>lombokartifactId>
version>1.16.20version>
dependency>
?
dependencies>
dependencyManagement>
搭建注册中心
dependencies>
dependency>
groupId>org.springframework.cloudgroupId>
artifactId>spring-cloud-starter-eureka-serverartifactId>
dependency>
dependency>
groupId>org.springframework.cloudgroupId>
artifactId>spring-cloud-starter-netflix-eureka-serverartifactId>
dependency>
dependency>
groupId>org.springframework.bootgroupId>
artifactId>spring-boot-devtoolsartifactId>
dependency>
dependencies>
server:
port: 8081
?
eureka:
instance:
hostname: 127.0.0.1
client:
fetch-registry: false
register-with-eureka: false
service-url:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
加入common
common-base层
dependencies>
dependency>
groupId>org.projectlombokgroupId>
artifactId>lombokartifactId>
dependency>
dependency>
groupId>tk.mybatisgroupId>
artifactId>mapper-spring-boot-starterartifactId>
dependency>
dependency>
groupId>tk.mybatisgroupId>
artifactId>mapperartifactId>
dependency>
dependencies>
common层
dependencies>
dependency>
groupId>org.projectlombokgroupId>
artifactId>lombokartifactId>
dependency>
dependency>
groupId>tk.mybatisgroupId>
artifactId>mapper-spring-boot-starterartifactId>
dependency>
dependency>
groupId>tk.mybatisgroupId>
artifactId>mapperartifactId>
dependency>
dependency>
groupId>com.zygroupId>
artifactId>cloud-common-baseartifactId>
version>1.0-SNAPSHOTversion>
dependency>
dependencies>
import lombok.AllArgsConstructor;
import lombok.Data;
?
import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Table;
?
@Data
@AllArgsConstructor
@Table(name = "user")
public class User {
?
@Id
private Long id;
?
@Column(name = "name")
private String name;
?
@Column(name = "status")
private Integer status;
}
import com.zy.entity.dto.BaseDTO;
import lombok.Data;
import lombok.experimental.Accessors;
?
import javax.persistence.Column;
import javax.persistence.Table;
?
@Data
@Accessors(chain = true)
@Table(name = "user")
public class UserDTO extends BaseDTO {
?
@Column(name = "name")
private String name;
?
}
上一篇:Java 多线程(进程终止)
下一篇:c语言字母大小写转换
文章标题:搭建简单的SpringCloud项目一:注册中心和公共层
文章链接:http://soscw.com/index.php/essay/90167.html