• 四,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
  • 相关阅读:
    good course Very
    HTTP Hypertext Transfer Protocol Overview
    Linux下tar.xz结尾的文件的解压方法
    原来java HttpURLConnection本身就提供了chunk的支持,又是让人一惊啊
    牛人一枚
    V2EX › 花了3个晚上,把readability最新的1.7.1转成了python版的
    13.11. 惯例优先原则(convention over configuration)
    明尼苏达大学
    快速构建实时抓取集群 « 搜索技术博客-淘宝
    Java Practices > Home
  • 原文地址:https://www.cnblogs.com/devan/p/10917161.html
Copyright © 2020-2023  润新知