2.创建子工程 ly-commonorg.springframework.boot spring-boot-starter-parent2.1.6.RELEASE UTF-8 UTF-8 1.8 Greenwich.SR2 org.springframework.cloud spring-cloud-dependencies${spring-cloud.version} pom import
创建包名,导入工具类,并且导入依赖
org.springframework spring-webjavax.servlet javax.servlet-apiorg.springframework.boot spring-boot-starter-loggingcom.fasterxml.jackson.core jackson-databindorg.apache.commons commons-lang33.4 org.projectlombok lombokjoda-time joda-time
工具类
链接:https://pan.baidu.com/s/1xRKMo2b8yFlhr8jqTYJ2Ag
提取码:1ta1
可以查看前边的博客:nacos安装及基本介绍
4.搭建网关 ly-gateway 4.1添加依赖2.在com.leyou包下创建启动类 3.创建降级熔断处理业务 4.新建配置文件org.springframework.cloud spring-cloud-starter-gatewaycom.alibaba.cloud spring-cloud-starter-alibaba-nacos-discovery2.1.0.RELEASE org.springframework.cloud spring-cloud-starter-netflix-hystrixcom.leyou ly-common1.0-SNAPSHOT org.springframework.boot spring-boot-maven-plugin
server:
port: 10010
spring:
application:
name: api-gateway
cloud:
nacos:
discovery:
server-addr: 127.0.0.1:8848
gateway:
default-filters:
- name: Hystrix
args:
name: fallbackcmd
fallbackUri: forward:/fallback
routes:
- id: item-service # 路由id,可以随意写
# 代理的服务地址;lb表示负载均衡(从nacos中获取具体服务)
uri: lb://item-service
# 路由断言,可以配置映射路径
predicates:
- Path=/api/item/**
filters:
# 表示过滤1个路径,2表示两个路径,以此类推
- StripPrefix=2
hystrix:
command:
default:
execution:
isolation:
thread:
#设置API网关中路由转发请求的HystrixCommand执行超时时间
timeoutInMilliseconds: 5000
5.新建子工程POJO 方便后边统一管理实体等
5.1添加依赖
6.创建子工程feign 6.1导入依赖org.projectlombok lombokcom.baomidou mybatis-plus-core3.1.0
7.新建子模块item 7.1导入依赖org.springframework.cloud spring-cloud-openfeign-coreorg.springframework spring-web
7.2在ly-pojo模块下新建子模块 ly-pojo-item 并导入依赖 7.3在ly-item模块下新建启动类 7.4添加配置文件 并在ly-pojo-item下建实体类包com.leyou.item.pojocom.alibaba.cloud spring-cloud-starter-alibaba-nacos-discovery2.1.0.RELEASE org.springframework.boot spring-boot-starter-webmysql mysql-connector-javacom.baomidou mybatis-plus-boot-starter3.1.0 com.leyou ly-pojo-item1.0-SNAPSHOT com.leyou ly-common1.0-SNAPSHOT org.springframework.boot spring-boot-starter-testorg.springframework.boot spring-boot-maven-plugin
server:
port: 8081
spring:
application:
name: item-service
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql:///leyou?serverTimezone=UTC&characterEncoding=utf8&useUnicode=true&useSSL=true
username: root
password: root
cloud:
nacos:
discovery:
server-addr: 127.0.0.1:8848
mybatis-plus:
type-aliases-package: com.leyou.item.pojo
configuration:
map-underscore-to-camel-case: true
logging:
level:
com.leyou: debug
8.数据库脚本
链接:https://pan.baidu.com/s/1tmLMU5R3oI4IAsZsV8tzaw
提取码:3gy5
链接:https://pan.baidu.com/s/1jYE-lzVmwDJa5DbTiYjWXA
提取码:ixdu
拉下用idea打开
运行命令:
npm run serve



