网关zuul,首先加入依赖包
<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>
yml文件:
server: port: 9527 spring: application: name: microservicecloud-zuul-gateway #微服务的名称 eureka: client: service-url: defaultZone: http://locahost:7001 instance: instance-id: gateway.com prefer-ip-address: true #显示ip
zuul: #添加映射
routes:
myurl.serviceId: microservicecloud
myurl.path: /myurl/**
ignored-services: microservicecloud # 忽略 微服务名,加微微服务名会报错
启动类:
@SpringBootApplication @EnableZuulProxy public class ZuulSpringCloudApp { public static void main(String[] args) { SpringApplication.run(ZuulSpringCloudApp.class,args); } }