springCloud(十三) spring cloud api网关 -zuul

2021-05-04 16:27

阅读:428

标签:desc   info   pac   server   项目配置   lease   str   设置   book   

1: 相关图片

技术图片技术图片技术图片技术图片技术图片

2:项目配置

1: pom.xml

4.0.0org.springframework.boot
        spring-boot-starter-parent
        2.3.1.RELEASEcom.itlaoqi.springcloud
    zuul
    0.0.1-SNAPSHOTzuulDemo project for Spring Boot1.8Hoxton.SR6aliyun-nexushttp://maven.aliyun.com/nexus/content/groups/public/aliyun-publichttps://maven.aliyun.com/repository/publicaliyun-jcenterhttps://maven.aliyun.com/repository/jcenteraliyun-pluginhttp://maven.aliyun.com/nexus/content/groups/public/falseorg.springframework.boot
            spring-boot-starter-web
        org.springframework.cloud
            spring-cloud-starter-netflix-eureka-client
        org.springframework.cloud
            spring-cloud-starter-netflix-zuul
        org.springframework.boot
            spring-boot-starter-test
            testorg.junit.vintage
                    junit-vintage-engine
                org.springframework.cloud
                spring-cloud-dependencies
                ${spring-cloud.version}pomimportorg.springframework.boot
                spring-boot-maven-plugin
            

2: ZuulApplication.java

package com.itlaoqi.springcloud.zuul;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
@EnableEurekaClient
@EnableZuulProxy
public class ZuulApplication {

    public static void main(String[] args) {
        SpringApplication.run(ZuulApplication.class, args);
    }

}

3: 配置文件

spring:
  application:
    name: zuul-proxy
eureka:
  client:
    service-url:
      defaultZone:
        http://localhost:8761/eureka
zuul:
  routes:
    book-service-api:
      path: /book/**                 #从zuul这端做的映射
      serviceId: book-service  #微服务名称
    member-service-api:
      path: /member/**
      serviceId: member-service  
server:
  port: 80

3: 浏览器访问

http://localhost/book/test?param=123
{"param":"123","port":8081}

http://localhost/member/sendMess?phone=123
{"code":0,"message":"发送短信成功,手机号为:123"}

3: Zuul 进行负载均衡设置

技术图片技术图片技术图片

springCloud(十三) spring cloud api网关 -zuul

标签:desc   info   pac   server   项目配置   lease   str   设置   book   

原文地址:https://www.cnblogs.com/guhualin/p/13194527.html


评论


亲,登录后才可以留言!