当前位置: 首页> 科技> 名企 > 优秀产品创意设计案例_网站制作过程合理的步骤是( )_太原推广团队_数据分析师培训机构推荐

优秀产品创意设计案例_网站制作过程合理的步骤是( )_太原推广团队_数据分析师培训机构推荐

时间:2025/7/11 18:16:10来源:https://blog.csdn.net/qq_40603125/article/details/145567677 浏览次数:0次
优秀产品创意设计案例_网站制作过程合理的步骤是( )_太原推广团队_数据分析师培训机构推荐

什么是网关

背景

单体项目中,前端只用访问指定的一个端口8080,就可以得到任何想要的数据

在这里插入图片描述

微服务项目中,ip是不断变化的,端口是多个的

在这里插入图片描述

解决方案:网关

网关:就是网络的关口,负责请求的路由、转发、身份校验

在这里插入图片描述
在这里插入图片描述

前段还是访问之前的端口8080即可

在这里插入图片描述

后端对于前端来说是透明的

在这里插入图片描述

网关的两种实现

网关是一种开发规范,实际的实现有两种:

  • 官方
  • 网飞公司

在这里插入图片描述

步骤

在这里插入图片描述

maven坐标

在hm-gateway模块的pom.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"><parent><artifactId>hmall</artifactId><groupId>com.heima</groupId><version>1.0.0</version></parent><modelVersion>4.0.0</modelVersion><artifactId>hm-gateway</artifactId><properties><maven.compiler.source>11</maven.compiler.source><maven.compiler.target>11</maven.compiler.target></properties><dependencies><!--common--><dependency><groupId>com.heima</groupId><artifactId>hm-common</artifactId><version>1.0.0</version></dependency><!--网关--><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-gateway</artifactId></dependency><!--nacos discovery--><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-loadbalancer</artifactId></dependency></dependencies><build><finalName>${project.artifactId}</finalName><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build>
</project>

启动类

在hm-gateway模块的com.hmall.gateway包下新建一个启动类:

package com.hmall.gateway;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication
public class GatewayApplication {public static void main(String[] args) {SpringApplication.run(GatewayApplication.class, args);}
}

测试

启动GatewayApplication,以 http://localhost:8080 拼接微服务接口路径来测试。例如:
http://localhost:8080/items/page?pageNo=1&pageSize=1

在这里插入图片描述

关键字:优秀产品创意设计案例_网站制作过程合理的步骤是( )_太原推广团队_数据分析师培训机构推荐

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: