<tbody id="j99e4"></tbody>

<dd id="j99e4"></dd>

  • <button id="j99e4"><object id="j99e4"></object></button>
      1. <th id="j99e4"></th>
        <button id="j99e4"><acronym id="j99e4"></acronym></button><rp id="j99e4"><object id="j99e4"><input id="j99e4"></input></object></rp>

        SpringCloud Gateway 快速入門_01
        2022-09-06 22:41:44


        文章目錄

        一、網關模塊搭建
        1. 引入依賴
        <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.2.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
        </parent>

        <properties>
        <spring.cloud-version>Hoxton.SR9</spring.cloud-version>
        </properties>
        <dependencies>
        <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-gateway</artifactId>
        </dependency>
        </dependencies>

        <dependencyManagement>
        <!--https://github.com/alibaba/spring-cloud-alibaba/wiki/%E7%89%88%E6%9C%AC%E8%AF%B4%E6%98%8E-->
        <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>
        2. 配置

        訪問??product.gblfy.com**???就會路由到??http://localhost:9000?? 這里的9000端口我們的產品服務模塊

        server:
        port: 8081
        spring:
        cloud:
        gateway:
        routes:
        - id: product
        uri: http://localhost:9000
        predicates:
        - Host=product.gblfy.com**
        3. 啟動類
        package com.gblfy.gatewayserv;

        import org.springframework.boot.SpringApplication;
        import org.springframework.boot.autoconfigure.SpringBootApplication;

        @SpringBootApplication
        public class GatewayServApplication {

        public static void main(String[] args) {
        SpringApplication.run(GatewayServApplication.class, args);
        }

        }
        二、產品服務模塊搭建
        2.1. 引入依賴
        <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.2.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
        </parent>
        <dependencies>
        <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!--服務注冊發現-->
        <dependency>
        <groupId>com.alibaba.cloud</groupId>
        <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
        </dependency>
        <dependency>
        <groupId>com.alibaba.cloud</groupId>
        <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
        </dependency>
        <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        </dependencies>
        <dependencyManagement>
        <dependencies>
        <!--spring-cloud-alibaba 版本控制-->
        <dependency>
        <groupId>com.alibaba.cloud</groupId>
        <artifactId>spring-cloud-alibaba-dependencies</artifactId>
        <version>2.2.6.RELEASE</version>
        <type>pom</type>
        <scope>import</scope>
        </dependency>
        </dependencies>
        </dependencyManagement>
        2.2. 配置
        server:
        port: 9000
        management:
        endpoints:
        web:
        exposure:
        include: '*'
        2.3. 控制層
        package com.gblfy.controller;

        import org.springframework.web.bind.annotation.GetMapping;
        import org.springframework.web.bind.annotation.PathVariable;
        import org.springframework.web.bind.annotation.RestController;

        @RestController
        public class ProductController {

        //http://localhost:9000/product/" + productId
        @GetMapping("/product/{productId}")
        public String getProductName(@PathVariable Integer productId) {
        return "IPhone 12";
        }
        }
        2.4. 啟動類
        package com.gblfy;

        import org.springframework.boot.SpringApplication;
        import org.springframework.boot.autoconfigure.SpringBootApplication;

        @SpringBootApplication
        public class ProductAplication {

        public static void main(String[] args) {
        SpringApplication.run(ProductAplication.class);
        }
        }
        2.5. 啟動產品模塊

        SpringCloud Gateway 快速入門_01_spring

        三、啟動中間件
        3.1. nacos啟動

        SpringCloud Gateway 快速入門_01_spring_02

        3.2. 啟動gateway

        SpringCloud Gateway 快速入門_01_中間件_03

        3.3. 配置域名映射

        SpringCloud Gateway 快速入門_01_版本控制_04

        四、測試驗證
        4.1. 測試產品服務

        ??http://localhost:9000/product/1??

        SpringCloud Gateway 快速入門_01_中間件_05

        4.2. 網關訪問產品

        通過網關gateway訪問產品模塊服務

        ??http://product.gblfy.com:8081/product/1??

        SpringCloud Gateway 快速入門_01_網關服務_06


        本文摘自 :https://blog.51cto.com/g


        更多科技新聞 ......

        亚洲人成图偷偷小说_亚洲图片小说激情综合_国产精品亚洲自在线播放页码_久久综合亚洲色hezyo国产
        <tbody id="j99e4"></tbody>

        <dd id="j99e4"></dd>

      2. <button id="j99e4"><object id="j99e4"></object></button>
          1. <th id="j99e4"></th>
            <button id="j99e4"><acronym id="j99e4"></acronym></button><rp id="j99e4"><object id="j99e4"><input id="j99e4"></input></object></rp>