Zuul代理不路由

时间:2018-08-17 06:13:55

标签: java spring netflix-zuul netflix-eureka

在使用Spring Microservices时,我无法通过zuul代理路由api

这是我的代码

eurka​​:

application.yml

spring:
  application:
    name: api
  cloud:
    config:
      enabled: true

server:
  port: ${PORT:8761}


eureka:
  client:
    registerWithEureka: false
    fetchRegistry: false
    serviceUrl:
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
  instance:
    hostname: localhost

zuul:

application.yml

spring:
  application:
    name: proxy-server

server:
  port: 8079

eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka
  fetchRegistry: true

zuul:
  ignored-services: '*'
  prefix: /api
  routes:
    account:
        path: /account/**
        serviceId: account
        stripPrefix: false
  host:
    socket-timeout-millis: 30000

ribbion:
  eureka:
    enabled: true

帐户 application.yml

ribbion:
  eureka:
    enabled: true


eureka:
  instance:
    preferIpAddress: true
  client:
    serviceUrl:
      defaultZone: ${EUREKA_URI:http://localhost:8761/eureka}
    instance:
      preferIpAddress: true

依赖性:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>Finchley.SR1</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

现在,URL localhost:8080/user/可以正常工作,但是localhost:8080/api/account/user/抛出404。

不确定我在这里做错什么,任何见解都会有所帮助,如果您需要其他详细信息,请告诉我

2 个答案:

答案 0 :(得分:0)

您需要做的是

  1. 使用Zuul作为依赖项生成Spring引导项目。
  2. @EnableZuulProxy注释主类
  3. application.properties文件中配置路由和端点
  4. 构建并启动服务

我建议首先执行上述步骤并使它们起作用。然后根据您的需要自定义该项目。在下面的文章中找到了上述步骤的详细说明。 How to build an API-Gateway with Netflix Zuul + Spring Boot

答案 1 :(得分:0)

我认为您忘记了在帐户application.yml中添加帐户服务的名称

spring:
     application:
           name: account