一:微服务项目整合
在https://github.com/shi469391tou/microservice-mallmanagement.git地址下载项目,并导入eclipse
1.1项目结构预览
microservice-eureka-server:用于服务注册发现
microservice-gateway-zuul:用于API网关
microservice-orderservice:用于订单管理服务
microservice-userservice:用于用户管理服务
1.2项目功能介绍
(1)microservice-eureka-server(Eureka 注册中心)
#该子项目使用了Spring Could的组件Eureka,主要用于搭建一个服务注册中心,microservice-gateway-zuul、microservice-orderservice、microservice-userservice都将通过配置注册到该注册中心
对应的配置文件application.yml代码如下:
spring:
application:
name: eureka-server #指定应用名称
server:
port: 8761
eureka:
#instance:
#hostname: localhost
client:
register-with-eureka: false
fetch-registry: false
service-url:
defaultZone: http://localhost:${server.port}/eureka/
#defaultZone: http://eureka-server:${server.port}/eureka/
#server:
#enable-self-preservation: false
(2)microservice-gateway-zuul(Zuul API 网关)
#该项目使用了Spring Could 的组件Zuul,主要作为其他微服务项目的API网关,来实现其他微服务接口的动态代理,microservice-orderservice和microservice-userservice微服务都可以使用Zuul网关服务进行代理请求。
对应的配置文件application.yml代码如下:
server:
port: 8050
eureka:
#instance:
#prefer-ip-address: true
client:
#配置Eureka注册中心地址
service-url:
defaultZone: http://localhost:8761/eureka/
#defaultZone: http://eureka-server:8761/eureka/
#service-url:
#defaultZone: http://localhost:8761/eureka/
spring:
application:
name: gateway-zuul
#配置serviceId为user-service和order-service的两个应用的路径映射
zuul:
ignoredServices: '*'
routes:
#order-url:
#path: /order-url/**
#url: http://localhost:7901/
user-service:
path: /user-service/**
serviceId: user-service
order-service:
path: /order-service/**
serviceId: order-service
(3)microservice-orderservice(订单管理微服务)
#该子项目就是一个使用传统的spring Boot 框架开发的订单管理微服务项目,主要用于商城订单管理,并提供有关订单管理的RESTFUL风格的API接口方法
对应的配置文件application.yml代码如下:
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/microservice_mallmanagemen
username: root
password: 123456
application:
name: order-service # 指定应用名称
server:
port: 7900 # 指定该Eureka实例的端口号
eureka:
client:
#配置Eureka注册中心地址
service-url:
defaultZone: http://