1.建立项目名字为microservice-gateway-zuul的项目
2.增加依赖:
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-zuul</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka</artifactId> </dependency>3.修改yml:
server: port: 8050 eureka: instance: #定义Eureka实例 hostname: localhost #Eureka实例所在的主机名 prefer-ip-address: true client: service-url: defaultZone: http://localhost:8761/eureka/ spring: application: name: microservice-gateway-zuul #名字 zuul: routes: order-serviceId: path:/order/** service-id:microservice-order4.启动类添加注解:@EnableZuulProxy
package com.itheima.microservicegatewayzuul; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.netflix.zuul.EnableZuulProxy; @SpringBootApplication @EnableZuulProxy public class MicroserviceGatewayZuulApplication { public static void main(String[] args) { SpringApplication.run(MicroserviceGatewayZuulApplication.class, args); } }5.启动eureka,order,zuul项目:
浏览器输入:http://localhost:8050/microservice-order/order/1
网关设置成功。
