亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

【金秋打卡】第2天 使用Maven搭建SpringCloud項目

標簽:
Spring Cloud

课程名称:Spring Cloud+ Vue前后端分离开发企业级在线视频系统

课程章节:第2章 使用Maven搭建SpringCloud项目

讲师姓名:甲蛙老师

课程内容

①搭建业务模块-system:新建maven项目并将其改造为最基本的Spring Boot项目,添加到注册中心

②搭建路由模块-gateway:新建项目添加gateway依赖,在gateway中添加system路由转发配置

课程收获

添加system服务的方法:

①新建一个Maven项目,注意将其的父项目改为主项目

②新建的项目添加SpringBoot与eureka-client依赖

<dependency>
    <
groupId>org.springframework.cloud</groupId>
    <
artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</
dependency>
<
dependency>
    <
groupId>org.springframework.boot</groupId>
    <
artifactId>spring-boot-starter-web</artifactId>
</
dependency>

②配置文件

spring.application.name=system
server.port=9001
eureka.instance.hostname=localhost
eureka.client.service-url.defaultZone=http://${eureka.instance.hostname}:8000/eureka/
server.servlet.context-path=/system


③添加注解

@EnableEurekaClient


但如果不加该注解也可以成功,应该是在添加依赖时自动添加到注册中心

添加路由模块-gateway的方法:

①添加依赖

<dependency>
    <
groupId>org.springframework.cloud</groupId>
    <
artifactId>spring-cloud-starter-gateway</artifactId>
</
dependency>


并且因为网关模块也是一个eureka-client所以也需要添加相关依赖。

②配置网关

# 路由转发配置
# 要转发的路由
# 9001地址对外隐藏,暴露9000地址 若访问localhost:9000/system/** 实际处理的是localhost:9001/system/**
spring.cloud.gateway.routes[0].id=system
spring.cloud.gateway.routes[0].uri=http://${eureka.instance.hostname}:9001
# 基于路径进行转发 只要路径包括"/system/**"就进行转发
spring.cloud.gateway.routes[0].predicates[0].name=Path
spring.cloud.gateway.routes[0].predicates[0].args[0]=/system/**


若以后需要添加其他路由将数组的0改为其他数字即可

 

https://img1.sycdn.imooc.com/63560bca000160a319201048.jpg

點擊查看更多內容
TA 點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優質文章

正在加載中
  • 推薦
  • 評論
  • 收藏
  • 共同學習,寫下你的評論
感謝您的支持,我會繼續努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學

大額優惠券免費領

立即參與 放棄機會
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號

舉報

0/150
提交
取消