5zuul 路由网关

本文介绍了如何使用Zuul作为路由网关。首先,需要引入相关依赖,接着详细讲解了配置的编写,包括在启动类上添加@EnableZuulProxy注解。最后,通过设置不同端口(7001, 8001, 80, 9527)进行了测试。" 133207345,19974089,探索.NET Core/.NET生态:ASP.NET Core和EF Core新特性解析,"['.NET', 'ASP.NET Core', 'EF Core', '跨平台开发', '数据库']
摘要由CSDN通过智能技术生成

#介绍
在这里插入图片描述

在这里插入图片描述

2 使用

2.1引入依赖

<!--        zuul的依赖-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-zuul</artifactId>
            <version>1.4.6.RELEASE</version>
        </dependency>

2.2编写配置

server:
  port: 9527

spring:
  application:
    name: springcloud-zuul

eureka:
  client:
    service-url:
      defaultZone:  http://127.0.0.1:7001/eureka/,http://127.0.0.1:7002/eureka/,http://127.0.0.1:7003/eureka/
    instance:
      #可以将localhost改为(klz.com域名)
      #我这里不想改C:\Windows\System32\drivers\etc\host文件的配置所以访问的时候把localhost当成klz.com使用
      instance-id:  klz.com
      prefer-ip-address: true

info:
  app.name: klz-springcloud
  company.name: klz.com

zuul:
  routes:
    mydept.serviceId: springcloud-provider-dept
    mydept.path: /mydept/**                         #将服务名改一个名字代替服务名
  ignored-services: springcloud-provider-dept       #忽略服务名,不能用服务名访问了
  prefix:                                           #设置公共前缀

2.23启动类上添加注解

@EnableZuulProxy

package com.common.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);
    }
}

2.24测试

开启7001.8001,80,9527
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值