项目集成GateWay

文章目录

1.环境搭建

1.创建sunrays-common-cloud-gateway-starter模块
2.目录结构
3.自动配置
1.GateWayAutoConfiguration.java
java 复制代码
package com.sunxiansheng.cloud.gateway.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;

/**
 * Description: GateWay自动配置类
 *
 * @Author sun
 * @Create 2025/1/7 17:19
 * @Version 1.0
 */
@Slf4j
@Configuration
public class GateWayAutoConfiguration {

    /**
     * 自动配置成功日志
     */
    @PostConstruct
    public void logConfigSuccess() {
        log.info("GateWayAutoConfiguration has been loaded successfully!");
    }
}
2.spring.factories
java 复制代码
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.sunxiansheng.cloud.gateway.config.GateWayAutoConfiguration
3.pom.xml
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>com.sunxiansheng</groupId>
        <artifactId>sunrays-common-cloud</artifactId>
        <version>2.0.0</version>
    </parent>

    <artifactId>sunrays-common-cloud-gateway-starter</artifactId>

    <dependencies>
        <!-- geteway -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-gateway</artifactId>
            <!-- 排除logging -->
            <exclusions>
                <exclusion>
                    <artifactId>spring-boot-starter-logging</artifactId>
                    <groupId>org.springframework.boot</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <!-- 负载均衡器,网关使用lb方式时引入 -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-loadbalancer</artifactId>
        </dependency>
        <!-- Nacos的服务发现,如果GateWay需要动态路由时引入 -->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
        </dependency>
    </dependencies>
</project>
4.注意:GateWay不能跟Web一起引入!
相关推荐
心灵宝贝1 小时前
申威架构ky10安装php-7.2.10.rpm详细步骤(国产麒麟系统64位)
开发语言·php
lly2024061 小时前
PHP 字符串操作详解
开发语言
像是套了虚弱散2 小时前
DevEco Studio与Web联合开发:打造鸿蒙混合应用的全景指南
开发语言·前端·华为·harmonyos·鸿蒙
旭意2 小时前
C++蓝桥杯之结构体10.15
开发语言·c++
毕设源码-赖学姐3 小时前
【开题答辩全过程】以 基于Android的校园快递互助APP为例,包含答辩的问题和答案
java·eclipse
damo013 小时前
stripe 支付对接
java·stripe
麦麦鸡腿堡4 小时前
Java的单例设计模式-饿汉式
java·开发语言·设计模式
简单点了4 小时前
go前后端项目的启动 、打包和部署
开发语言·后端·golang
假客套4 小时前
Request method ‘POST‘ not supported,问题分析和解决
java
傻童:CPU4 小时前
C语言需要掌握的基础知识点之前缀和
java·c语言·算法