**超级简单的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

猜你喜欢

转载自blog.csdn.net/weixin_44421448/article/details/86294771
今日推荐