3.1 ZuulProxy Gateway - fanpan26/Fly.SpringCloud GitHub Wiki

fly-gateway 项目添加引用

 <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-zuul</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
    </dependencies>
编写入口类,加上@EnableZuulProxy

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

resources中添加application.yml

server:
  port: 9001
spring:
  application:
    name: fly-gateway
eureka:
  client:
    serviceUrl:
      defaultZone: http://panzi:123456@eureka1:8761/eureka/,http://panzi:123456@eureka2:8762/eureka/
  instance:
    prefer-ip-address: true
    instanceId: ${spring.application.name}:${spring.application.instance_id:${server.port}}
    metadata-map:
      description: account service
management:
  endpoints:
    web:
      exposure:
        include: '*'
启动Eureka Server,Config Server,Account Service,Gateway.访问:http://localhost:9001/fly-account-service/testZuul

//返回正常,说明网关默认路由起作用
zuul test

参考文档

⚠️ **GitHub.com Fallback** ⚠️