栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

互联网技术-alibaba-gateway网关基本使用pom文件以及yml文件配置

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

互联网技术-alibaba-gateway网关基本使用pom文件以及yml文件配置

 

  • 1.创建项目:test-gateway-2.1

  • 2.修改pom文件,添加坐标

  • 
            
            
                org.springframework.cloud
                spring-cloud-starter-gateway
            
    
            
            
                com.alibaba.cloud
                spring-cloud-starter-alibaba-nacos-discovery
            
    
        

  • 配置 yml文件:application.yml(yml文件中的格式要严格遵守下列代码格式)

  • spring.cloud.gateway.discovery.locator.enabled为true,表明gateway开启服务注册和发现的功能,并且spring cloud gateway自动根据服务发现为每一个服务创建了一个router,这个router将以服务名开头的请求路径转发到对应的服务

    #端口号
    server:
      port: 10010
    spring:
      application:
        name: test-gateway
      cloud:
        nacos:
          discovery:
            server-addr: 127.0.0.1:8848   #nacos服务地址
        gateway:
          discovery:
            locator:
              enabled: true   #开启服务注册和发现的功能,自动创建router以服务名开头的请求路径转发到对应的服务
    

  • 编写启动类

    package com.czxy;
    
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
    
    
    @SpringBootApplication
    @EnableDiscoveryClient
    public class TestGatewayApplication {
        public static void main(String[] args) {
            SpringApplication.run(TestGatewayApplication.class, args);
        }
    
    }
    

    测试

  •  

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/998912.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号