海报在线制作免费网站,从哪里找网站,打字建站宝,笔趣阁 网站开发什么是网关
背景 单体项目中#xff0c;前端只用访问指定的一个端口8080#xff0c;就可以得到任何想要的数据 微服务项目中#xff0c;ip是不断变化的#xff0c;端口是多个的 解决方案#xff1a;网关 网关#xff1a;就是网络的关口#xff0c;负责请求的路由、转发…什么是网关
背景 单体项目中前端只用访问指定的一个端口8080就可以得到任何想要的数据 微服务项目中ip是不断变化的端口是多个的 解决方案网关 网关就是网络的关口负责请求的路由、转发、身份校验。 前段还是访问之前的端口8080即可 后端对于前端来说是透明的 网关的两种实现 网关是一种开发规范实际的实现有两种 官方网飞公司 步骤 maven坐标 在hm-gateway模块的pom.xml文件中引入依赖 ?xml version1.0 encodingUTF-8?
project xmlnshttp://maven.apache.org/POM/4.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdparentartifactIdhmall/artifactIdgroupIdcom.heima/groupIdversion1.0.0/version/parentmodelVersion4.0.0/modelVersionartifactIdhm-gateway/artifactIdpropertiesmaven.compiler.source11/maven.compiler.sourcemaven.compiler.target11/maven.compiler.target/propertiesdependencies!--common--dependencygroupIdcom.heima/groupIdartifactIdhm-common/artifactIdversion1.0.0/version/dependency!--网关--dependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-gateway/artifactId/dependency!--nacos discovery--dependencygroupIdcom.alibaba.cloud/groupIdartifactIdspring-cloud-starter-alibaba-nacos-discovery/artifactId/dependency!--负载均衡--dependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-loadbalancer/artifactId/dependency/dependenciesbuildfinalName${project.artifactId}/finalNamepluginsplugingroupIdorg.springframework.boot/groupIdartifactIdspring-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?pageNo1pageSize1