项目集成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一起引入!
相关推荐
蜡笔小新..36 分钟前
R语言和RStudio安装
开发语言·r语言
ALPH_36 分钟前
R语言的基础命令及实例操作
开发语言·数据分析·r语言·perl·r语言-4.2.1
咩咩觉主40 分钟前
C# &Unity 唐老狮 No.6 模拟面试题
开发语言·unity·面试·c#·游戏引擎·唐老师
╰つ゛木槿3 小时前
Spring Boot 调用DeepSeek API的详细教程
java·spring boot·后端·deepseek
*.✧屠苏隐遥(ノ◕ヮ◕)ノ*.✧3 小时前
C语言_数据结构总结8:链式队列
c语言·开发语言·数据结构·链表·visualstudio·visual studio
千里码aicood3 小时前
[含文档+PPT+源码等]精品基于Python实现的校园小助手小程序的设计与实现
开发语言·前端·python
讨厌下雨的天空3 小时前
C++之list
开发语言·c++·list
大麦大麦4 小时前
深入剖析 Sass:从基础到进阶的 CSS 预处理器应用指南
开发语言·前端·css·面试·rust·uni-app·sass
hhw1991124 小时前
c#面试题整理6
java·开发语言·c#
蠟筆小新工程師4 小时前
Deepseek可以通过多种方式帮助CAD加速工作
开发语言·python·seepdeek