当前位置: 首页 > news >正文

四川建设人才网网站最新网站查询

四川建设人才网网站,最新网站查询,加强网站建设 统计局,导航网站建设创建SpringCloudGateWay 本案例基于尚硅谷《谷粒商城》项目&#xff0c;视频27 创建测试API网关 1、创建module 2、引入依赖 <?xml version"1.0" encoding"UTF-8"?> <project xmlns"http://maven.apache.org/POM/4.0.0" xmlns:x…

创建SpringCloudGateWay

本案例基于尚硅谷《谷粒商城》项目,视频27 创建测试API网关
1、创建module
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

输入gateway查找相关依赖
在这里插入图片描述

2、引入依赖

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.1.8.RELEASE</version><relativePath/> <!-- lookup parent from repository --></parent><groupId>com.atguigu.gulimall</groupId><artifactId>gulimall-gateway</artifactId><version>0.0.1-SNAPSHOT</version><name>gulimall-gateway</name><description>API网关</description><properties><java.version>1.8</java.version><spring-cloud.version>Greenwich.SR3</spring-cloud.version></properties><dependencies><!--gulimall-common中依赖了服务注册与发现,将网关服务注册到服务中心--><dependency><groupId>com.atguigu.gulimall</groupId><artifactId>gulimall-common</artifactId><version>1.0-SNAPSHOT</version></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-gateway</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency></dependencies><dependencyManagement><dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-dependencies</artifactId><version>${spring-cloud.version}</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>

3、开启服务注册与发现
3.1

@EnableDiscoveryClient//加入该注解
@SpringBootApplication
public class GulimallGatewayApplication {public static void main(String[] args) {SpringApplication.run(GulimallGatewayApplication.class, args);}}

3.2 修改application.properties文件,将服务注册到nacos

#配置nacos注册中心地址
spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848
#服务名称
spring.application.name=gulimall-gateway

3.3
在nacos页面创建网关命名空间
在这里插入图片描述
在这里插入图片描述
创建配置
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

创建bootstrap.properties

spring.application.name=gulimall-gateway
#配置中心地址
spring.cloud.nacos.config.server-addr=127.0.0.1:8848
#命名空间id
spring.cloud.nacos.config.namespace=d6130a53-dcca-4e67-888c-a236b16f5f87

3.4

启动类添加排除数据库配置代码(exclude = DataSourceAutoConfiguration.class)

@EnableDiscoveryClient
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
public class GulimallGatewayApplication {public static void main(String[] args) {SpringApplication.run(GulimallGatewayApplication.class, args);}}```否则项目启动报错:```xml
***************************
APPLICATION FAILED TO START
***************************Description:Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.Reason: Failed to determine a suitable driver classAction:Consider the following:If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).Process finished with exit code 1

3.5 配置网关模块的端口号为88
在这里插入图片描述

3.6 配置网关地址:
如果请求路径中有qq就跳转到https://www.qq.com
如果请求路径中有baidu,就跳转到https://www.baidu.com
新建一个
application.yml,内容如下

spring:cloud:gateway:routes:- id: test_routeuri: https://www.baidu.compredicates:- Query=url,baidu- id: test_routeuri: https://www.qq.compredicates:- Query=url,qq

4、测试如下
浏览器输入地址:
http://localhost:88/hello?url=qq
跳转到(实际访问的地址是 https://www.qq.com/hello 因为qq网址中没有hell):

浏览器输入地址:
http://localhost:88/hello?url=baidu
跳转如下(实际访问的地址是 https://www.baidu.com/hello 因为百度中也没有包含hell的地址):
在这里插入图片描述

http://www.hkea.cn/news/303247/

相关文章:

  • 北京微信网站建设费用想卖产品怎么推广宣传
  • 网站上线的步骤厦门网站推广公司哪家好
  • 网站做app的软件有哪些百度一下你就知道下载
  • 界面设计的重要性百度seo关键词排名推荐
  • 股票做T网站直播营销
  • 北京手机网站建设公司排名技术优化seo
  • wordpress可爱的主题seo优化教程
  • 自己可以申请网站做外卖吗网站描述和关键词怎么写
  • 公司网站网页设计seo站长工具推广平台
  • 重庆南岸营销型网站建设公司哪家专业真实的网站制作
  • 郑州企业网站建设兼职推广渠道
  • 网站哪些数据优化大师的作用
  • 政府网站集约化建设总结营销软文推广平台
  • 学网站开发跟那个专业最相近百度站长平台注册
  • 网站开发python电脑培训班有哪些科目
  • 惠州响应式网站哪家好云盘搜索
  • spring做网站合肥seo排名收费
  • 做58网站怎么赚钱二十个优化
  • 做企业手机网站北京seo网站开发
  • 关于网站建设中原创文章的一些想法体育热点新闻
  • 天河做网站开发免费留电话号码的广告
  • 成都市金堂县网站建设免费seo在线工具
  • 计算机培训中心网站高端网站建设的公司
  • 成都建设路小学网站大作设计网站
  • 桂林创新大厦网站今日十大热点新闻事件
  • 做网站空间哪家好windows7系统优化工具
  • 网站建设首选公司seo推广一个月见效
  • 微信做模板下载网站有哪些推广网站要注意什么
  • 做网站 java c常德seo快速排名
  • 仙桃做网站找谁常用的网络推广方法