zoukankan      html  css  js  c++  java
  • 四,Spring Cloud 网关

    Spring Cloud 网关 EnableZuulProxy

    新建项目 ApiGetway

    pom.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <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>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.0.9.RELEASE</version>
            <relativePath/> <!-- lookup parent from repository -->
        </parent>
        <groupId>com.example</groupId>
        <artifactId>demo</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <name>demo</name>
        <description>Demo project for Spring Boot</description>
    
    
        <properties>
            <java.version>1.8</java.version>
            <spring-cloud.version>Finchley.SR2</spring-cloud.version>
        </properties>
    
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter</artifactId>
            </dependency>
    
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
            </dependency>
    
            <!--网关-->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-netflix-zuul</artifactId>
            </dependency>
    
        </dependencies>
    
        <dependencyManagement>
            <dependencies>
                <dependency>
                    <groupId>org.springframework.cloud</groupId>
                    <artifactId>spring-cloud-dependencies</artifactId>
                    <version>${spring-cloud.version}</version>
                    <type>pom</type>
                    <scope>import</scope>
                </dependency>
            </dependencies>
        </dependencyManagement>
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
            </plugins>
        </build>
    
    </project>
    DemoApplication.java
    package com.example.demo;
    
    import ...
    
    @SpringCloudApplication
    @EnableZuulProxy
    public class DemoApplication {
    
        public static void main(String[] args) {
            SpringApplication.run(DemoApplication.class, args);
        }
    
    }

    application.yml

    server:
      port: 5555
    spring:
      application:
        name: api-gateway
    
    
    eureka:
      client:
        service-url:
          defaultZone: http://localhost:1313/eureka/
    zuul:
      routes:
        api-a-url:
          path: /a/**
          url: http://localhost:8080/
        api-b-url:
              path: /b/**
              url: http://localhost:8090/

    启动相关的服务

    分别访问

    http://localhost:5555/a/hello?name=AAAA

    http://localhost:5555/b/hello?name=BBBB

    EnableZuulProxy
  • 相关阅读:
    你最喜欢的程序员漫画
    编程名言名句
    查看一个数是不是2的n次方
    程序员需要有多懒 ?- cocos2d-x 数学函数、常用宏粗整理
    C++中string、int、char之间转换
    cocos2d-x 中使用 srand((unsigned)time(NULL))重新设置一个随机种子
    ASP.NET MVC SignalR 配合VUE
    VS Visual Studio光标无法自动到行尾,点哪里就在哪里解决办法
    .NET Core Entity Framework 代码优先配置
    Image Bitmap转MemoryStream后,上传遇到问题,报Index异常
  • 原文地址:https://www.cnblogs.com/devan/p/10917161.html
Copyright © 2011-2022 走看看