欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

springcloud zuul 入门配置

程序员文章站 2022-03-03 12:25:06
核心代码pom.xmlorg.springframework.cloudspring-cloud-starter-eurekaorg.springframework.cloud&l...

1、zuul-Service 网关服务的核心代码

pom.xml

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

<!-- 热部署插件 -->
<dependency>
	<groupId>org.springframework</groupId>
	<artifactId>springloaded</artifactId>
</dependency>

<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-devtools</artifactId>
</dependency>

yml

server: 
  port: 9500
 
spring: 
  application:
    name: microservicecloud-zuul
 
eureka: 
  client: 
    service-url: 
      defaultZone: http://eureka7001.com:7001/eureka,http://eureka7002.com:7002/eureka,http://eureka7003.com:7003/eureka  
  instance:
    instance-id: gateway9500.com
    prefer-ip-address: true 
 

zuul: 
  prefix: /myzuul
 # ignored-services: microservicecloud-order  # 忽略单个服务名称
  ignored-services: "*"                       # 忽略所有的服务名称
  routes: 
    myorder.serviceId: microservicecloud-order
    myorder.path: /myorder/**

SpringBootApplication.java

@SpringBootApplication
@EnableZuulProxy
public class Zuul_SpringApplication{

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

orderService微服务 的不是本文的重点,配置省略。

2、测试

先启动 Eureka,
再先启动 orderService 服务
最后启动 ZuulService 服务

先访问 order 服务, http://localhost:8001/order/get/2 ,响应请求的数据

再通过 zuul 服务, 请求 为 http://127.0.0.1:9500/myzuul/myorder/order/get/2 , 响应相同的数据。

3、相关文章推荐

https://cloud.spring.io/spring-cloud-netflix/reference/html/

https://www.cnblogs.com/jing99/p/11696192.html

https://www.jianshu.com/p/511db36c1b3e

本文地址:https://blog.csdn.net/xiaojin21cen/article/details/107376730