10.zuul路由网关

如何配置一个zuul:

1.pom文件

        <dependency>
            <groupId>com.wu</groupId>
            <artifactId>springcloud-api</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
        </dependency>
        <!--ribbon-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-ribbon</artifactId>
            <version>1.4.6.RELEASE</version>
        </dependency>
        <!--eureka-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka</artifactId>
            <version>1.4.6.RELEASE</version>
        </dependency>
        <!-- Hystrix 依赖-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-hystrix</artifactId>
            <version>1.4.6.RELEASE</version>
        </dependency>
        <!-- Hystrix 监控-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
            <version>1.4.6.RELEASE</version>
        </dependency>
<!-- zuul依赖-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-zuul</artifactId>
            <version>1.4.6.RELEASE</version>
        </dependency>

2. 配置文件

server:
  port: 9527
spring:
  application:
    name: springcloud-zull
eureka:
  client:
    service-url:
      #集群发布
      defaultZone: http://localhost:7001/eureka/,http://localhost:7002/eureka/,http://localhost:7003/eureka/
  instance:
    instance-id:  springcloud-zull #修改描述信息
    #prefer-ip-address: true #可以使用域名ip代替localhost:巴拉巴拉
info:
  app.name: wuyimin
  company: yuzhibo
zuul:
  routes:
    mydept.serviceId: springcloud-provider-dept
    mydept.path: /mydept/** #换成这个路径访问
  ignored-services: springcloud-provider-dept #不能使用这个路径访问了 也可以使用"*"来隐藏全部真实项目
  prefix: /wu #配置一个统一的前缀

3.主启动类

@SpringBootApplication
@EnableZuulProxy//开启zuul
public class zuulApplication_9527 {
    public static void main(String[] args) {
        SpringApplication.run(zuulApplication_9527.class,args);
    }
}

 

 启动效果

9527下只能通过此url访问

 

 当然8001原来的还是可以访问的

 

posted @ 2021-07-02 21:06  一拳超人的逆袭  阅读(46)  评论(0编辑  收藏  举报