zoukankan      html  css  js  c++  java
  • springcloud(12)-网关zuul

    1.创建网关项目zuul

    2.pom.xml

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <parent>
        <groupId>com.zhangdemo</groupId>
        <artifactId>springcloud</artifactId>
        <version>0.0.1-SNAPSHOT</version>
      </parent>
      <artifactId>productServiceZuul</artifactId>
    
      <dependencies>
        <dependency>
          <groupId>org.springframework.cloud</groupId>
          <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
        <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    
        <!--配置网关-->
        <dependency>
          <groupId>org.springframework.cloud</groupId>
          <artifactId>spring-cloud-starter-netflix-zuul</artifactId>
        </dependency>
      </dependencies>
    </project>
    

    3.ProductServiceZuulApplication

    @SpringBootApplication
    @EnableZuulProxy            //网关
    @EnableEurekaClient
    @EnableDiscoveryClient
    public class ProductServiceZuulApplication {
        public static void main(String[] args) {
            int port = 8040;
            if(!NetUtil.isUsableLocalPort(port)) {
                System.err.printf("端口%d被占用了,无法启动%n", port );
                System.exit(1);
            }
            new SpringApplicationBuilder(ProductServiceZuulApplication.class).properties("server.port=" + port).run(args);
    
        }
    }
    

    4.application.yml

    eureka:
      client:
        serviceUrl:
          defaultZone: http://localhost:8761/eureka/
    spring:
      application:
        name: product-service-zuul
    zuul:
      routes:
        api-a:
          path: /api-data/**
          serviceId: PRODUCT-DATA-SERVICE
        api-b:
          path: /api-view/**
          serviceId: PRODUCT-VIEW-SERVICE-FEIGN
    

    5.测试
    http://localhost:8040/api-data/products

    image-20201116152808748

    http://localhost:8040/api-view/products

    image-20201116152838818
  • 相关阅读:
    PHP 连接oracle
    PHP 简易导出excel 类解决Excel 打开乱码
    Linux下Apache网站目录读写权限的设置
    PHP behavior 机制简单实现
    RewriteCond和13个mod_rewrite应用举例Apache伪静态
    PHP event 事件机制
    PHP 函数引用传值
    django数据库连接快速配置
    解决Django项目数据库无法迁移问题
    生成uuid唯一标识符
  • 原文地址:https://www.cnblogs.com/NaoDaiYouDianDa/p/13985432.html
Copyright © 2011-2022 走看看