1. 程式人生 > >**超級簡單的Springboot + Springcloud 搭建分散式框架**

**超級簡單的Springboot + Springcloud 搭建分散式框架**

超級簡單的Springboot + Springcloud 搭建分散式框架

1. 註冊中心 Eureka

引入的資源,web,cloud Discovery:Eureka Server
啟動類:@EnableEurekaServer

配置檔案:
 #######eureka配置##########
     server.port=8888
# 不向註冊中心註冊自己
    eureka.client.register-with-eureka=false
# 不需要檢索服務
    eureka.client.fetch-registry=false
    eureka.client.serviceUrl.defaultZone=http://localhost:${server.port}/

服務中心 Server

引入的資源:`web , mysql, mybatis,cloud Discovery:Eureka Discovery`
  啟動類:`@EnableDiscoveryClient`
   配置檔案:
####訪問埠#####
    server.port=8885
###配置註冊中心###
    eureka.client.serviceUrl.defaultZone=http://localhost:8888/eureka/
###服務名###
    spring.application.name=mirco-user    
#配置資料庫連線    
    spring.datasource.url = jdbc:mysql://localhost:3306/shop_admin?   			     useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
    spring.datasource.username =root
    spring.datasource.password =root
    spring.datasource.driverClassName = com.mysql.jdbc.Driver

路由閘道器 gateway

引入的資源:web,Eureka Discovery,zuul,ribbon
啟動類:

@SpringCloudApplication
@EnableZuulProxy

配置檔案:

        server.port=8887
###配置註冊中心###    
        eureka.client.serviceUrl.defaultZone=http://localhost:8888/eureka/        
**路由所代理的服務**    
	####服務名####    
        spring.application.name=micro-gateway     
###商品的服務### 
        zuul.routes.orient-service-url.path=/gateway/**
        zuul.routes.orient-service-url.serviceId=mirco-shop

###購物車的服務###
       zuul.routes.carts-service-url.path=/carts/**
        zuul.routes.carts-service-url.serviceId=mirco-carts
    

 ###使用者的服務###
  zuul.routes.user-service-url.path=/user/**
    zuul.routes.user-service-url.serviceId=mirco-user


 #配置MySQL資料庫連線
 spring.datasource.url = jdbc:mysql://localhost:3306/shop_admin?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
    spring.datasource.username =root
    spring.datasource.password =root
    spring.datasource.driverClassName = com.mysql.jdbc.Driver

#配置MongoDB資料庫

    spring.data.mongodb.uri=mongodb://localhost:27017/shop_logs


    spring.main.allow-bean-definition-overriding=true
    zuul.host.socket-timeout-millis=60000
    zuul.host.connect-timeout-millis=10000
    hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=60000
    ribbon.eureka.enabled=true
    ribbon.http.client.enabled=false

前臺 Web專案

引入的資源:web,thyemleaf

配置檔案:

#配置thymeleaf
  spring.thymeleaf.prefix=classpath:/templates/
    spring.Thymeleaf.suffix=.html 
    spring.mvc.static-path-pattern=/static/**
    spring.thymeleaf.cache=false
    
    server.port=8082