SpringCloud Gateway(八)


搭建SpringCloud Gateway

    創建microservicecloud-springcloud-gateway-9528工程

     pom文件 依賴:

 <dependencies>
        <!-- 將微服務provider側注冊進eureka -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-gateway</artifactId>
        </dependency>
        <!-- swagger-spring-boot -->
        <dependency>
            <groupId>com.spring4all</groupId>
            <artifactId>swagger-spring-boot-starter</artifactId>
            <version>1.7.0.RELEASE</version>
        </dependency>
        <!--api接口-->
        <dependency>
            <groupId>com.yehui</groupId>
            <artifactId>microservicecloud-api</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
    </dependencies>

 

yml文件

server: port: 9528 spring: application: name: springcloudgetway cloud: gateway: discovery: locator: enabled: true lowerCaseServiceId: true routes: #id標簽配置的是router的id,每個router都需要一個唯一的id - id: dept_client #uri配置的是將請求路由到哪里, uri: lb://microservicecloud-dept
 predicates: - Path=/dept_client/client/** #如果請求地址滿足/microservicecloud-dept/**,則轉發到microservicecloud-dept服務 filters: - StripPrefix=2 eureka: client: #客戶端注冊進eureka服務列表內 service-url: defaultZone: http://localhost:7002/eureka/,http://localhost:7003/eureka/,http://localhost:7001/eureka/ instance: prefer-ip-address: true

 

啟動類

@SpringBootApplication public class SpringCloudGateWayApp { public static void main(String[] args) { SpringApplication.run(SpringCloudGateWayApp.class); } }

 

啟動服務測試;

訪問:http://localhost:9528/dept_client/client/dept/findAll

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM