zoukankan      html  css  js  c++  java
  • SpringCloudGateway 服务网关基础搭建

    1. 依赖

    <!-- 服务发现 -->
    <dependency>
        <groupId>com.alibaba.cloud</groupId>
        <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
    </dependency>
    <!-- 服务网关 -->
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-gateway</artifactId>
    </dependency>
    

    2. 配置

    spring:
      cloud:
        nacos:
          discovery:
            server-addr: localhost:8848
        gateway:
          globalcors:
            corsConfigurations:
              '[/**]':
                allowedOrigins: '*'
                allowedHeaders: '*'
                allowedMethods: '*'
                allowCredentials: true
          discovery:
            locator:
              enabled: true
              lowerCaseServiceId: true
    

    3. 启动类

    @SpringBootApplication
    @EnableDiscoveryClient
    public class GatewayApplication {
        public static void main(String[] args) {
            SpringApplication.run(GatewayApplication.class, args);
        }
    }
    

    4. 注意

    • 如果服务已经启用CORS过滤器,则无需再gateway上配置CORS否则会导致错误
    • 使用nacos做服务注册中心时,服务必须与gateway注册在同一个名空间以及分组下,才会被自动发现定位。
  • 相关阅读:
    九九乘法表
    计算器界面
    3.2封装的日期类
    杨辉三角
    100以内的素数
    九九 乘法表
    七、logging模块
    六、MySQLdb 模块
    四、浏览器运行模式
    五、configparser模块
  • 原文地址:https://www.cnblogs.com/luguojun/p/14294736.html
Copyright © 2011-2022 走看看