Zuul:路由网关

Zuul:路由网关_第1张图片

话不多说上实战

先建一个子模块

Zuul:路由网关_第2张图片 pom

 



    
        springcloud
        com.kuang
        1.0-SNAPSHOT
    
    4.0.0

    springcloud-zuul-9527

    
        8
        8
    

    
    


    

        
            org.springframework.cloud
            spring-cloud-starter-zuul
            1.4.6.RELEASE
        



        
        
            org.springframework.cloud
            spring-cloud-starter-hystrix
            1.4.6.RELEASE
        


        
        
            org.springframework.cloud
            spring-cloud-starter-hystrix-dashboard
            1.4.6.RELEASE
        


        
        
            org.springframework.cloud
            spring-cloud-starter-ribbon
            1.4.6.RELEASE
        

        
        
            org.springframework.cloud
            spring-cloud-starter-eureka
            1.4.6.RELEASE
        

        
            com.kuang
            springcloud-api
            1.0-SNAPSHOT
        
        
        
            org.springframework.boot
            spring-boot-starter-web
        
        
        
            org.springframework.boot
            spring-boot-devtools
        

    



yml

server:
  port: 9527
#微服务注册的名字
spring:
  application:
    name: springcloud-zuul
eureka:
  client:
    service-url:
      defaultZone: http://eureka7001.com:7001/eureka/,http://eureka7002.com:7002/eureka/,http://eureka7003.com:7003/eureka/
  instance:
    instance-id: zuul9527.com
    prefer-ip-address: true
info:
  app.name: kuang-springcloud
  company.name: blog.kuangstudy.com

主启动类

package com.kuang.springcloud;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;

@SpringBootApplication
@EnableZuulProxy//开启zuul代理
public class ZuulApplication_9527 {

    public static void main(String[] args) {
        SpringApplication.run(ZuulApplication_9527.class,args);
    }
}

启动

Zuul:路由网关_第3张图片

 Zuul:路由网关_第4张图片

 yml加个路径别名

server:
  port: 9527
#微服务注册的名字
spring:
  application:
    name: springcloud-zuul
eureka:
  client:
    service-url:
      defaultZone: http://eureka7001.com:7001/eureka/,http://eureka7002.com:7002/eureka/,http://eureka7003.com:7003/eureka/
  instance:
    instance-id: zuul9527.com
    prefer-ip-address: true
info:
  app.name: kuang-springcloud
  company.name: blog.kuangstudy.com

#路径别名
zuul:
  routes:
    mydept.serviceId: springcloud-provider-dept
    mydept.path: /mydept/**

启动服务

Zuul:路由网关_第5张图片

#路径别名
zuul:
  routes:
    mydept.serviceId: springcloud-provider-dept
    mydept.path: /mydept/**
  ignored-services: springcloud-provider-dept #不能再使用这个路径在访问了

 Zuul:路由网关_第6张图片

 

 

你可能感兴趣的:(SpringCloud,java)