您好,登錄后才能下訂單哦!
這篇文章將為大家詳細(xì)講解有關(guān)如何創(chuàng)建網(wǎng)關(guān)項目Spring Cloud Gateway,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。
創(chuàng)建網(wǎng)關(guān)項目
加入網(wǎng)關(guān)后微服務(wù)的架構(gòu)圖
創(chuàng)建項目
POM文件
<properties> <java.version>1.8</java.version> <spring-cloud.version>Greenwich.SR3</spring-cloud.version> </properties> <dependencies> <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>
修改配置文件
將項目目錄下的/src/main/resources/application.properties文件重命名為application.yml,properties配置格式和yml配置格式是等效的,而yml配置格式能更好的被配置中心使用,所以我們使用yml配置格式。
測試網(wǎng)關(guān)項目
application.yml配置文件內(nèi)容修改如下:
server: port: 9000 spring: cloud: gateway: routes: - id: first_route uri: https://github.com/sunweisheng predicates: - Path=/test
port:網(wǎng)關(guān)服務(wù)端口
routes:路由集合
id:路由的唯一標(biāo)示
uri:路由目標(biāo)地址
predicates:路由條件,如果為true則路由到uri
predicates(還有filters)的種類很多請參考Spring Cloud Gateway官網(wǎng)
啟動項目測試
訪問127.0.0.1:9000/test
關(guān)于“如何創(chuàng)建網(wǎng)關(guān)項目Spring Cloud Gateway”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,使各位可以學(xué)到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。