【问题标题】:Spring Boot 2 with Netflix Zuul not working?带有 Netflix Zuul 的 Spring Boot 2 不起作用?
【发布时间】:2018-09-17 16:57:29
【问题描述】:

我有一个非常简单的 Zuul 应用程序,我正在尝试运行它,只是为了让事情脱离实际,没有过滤器或类似的东西。我只是想为我想要测试的服务运行一个简单的传递。然而,Zuul 映射或路由似乎并未被创建,而且我的所有请求都得到了 404。

对于我的 zuul 边缘服务器,这是我的设置:

pom.xml:

    <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>gzuul</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>gzuul</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.5.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <spring-cloud.version>Finchley.SR1</spring-cloud.version>
    </properties>

    <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-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>


</project>

application.yml:

server:
  port: 8084
management:
  endpoints:
    web:
      exposure:
        include: "*"
  endpoint:
    mappings:
      enabled: true
    routes:
      enabled: true
zuul:
  routes:
    invoicing:
      path: /invoicing/**
      url: [url that I know works]/invoicing

还有我的“主”课:

package com.example.gzuul;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;

@EnableZuulProxy
@SpringBootApplication
public class GzuulApplication {

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

所以,是的,整体设置非常简单。

但是,每当我尝试访问像 localhost:8084/invoicing/[some stuff to pass through] 这样的 url 时,我都会收到以下错误:

2018-09-17 11:55:19.625 DEBUG 34902 --- [nio-8084-exec-1] s.b.a.e.w.s.WebMvcEndpointHandlerMapping : Looking up handler method for path /invoicing/v1/invoice/7900007809
2018-09-17 11:55:19.629 DEBUG 34902 --- [nio-8084-exec-1] s.b.a.e.w.s.WebMvcEndpointHandlerMapping : Did not find handler method for [/invoicing/v1/invoice/7900007809]
2018-09-17 11:55:19.629 DEBUG 34902 --- [nio-8084-exec-1] a.e.w.s.ControllerEndpointHandlerMapping : Looking up handler method for path /invoicing/v1/invoice/7900007809
2018-09-17 11:55:19.629 DEBUG 34902 --- [nio-8084-exec-1] a.e.w.s.ControllerEndpointHandlerMapping : Did not find handler method for [/invoicing/v1/invoice/7900007809]

此外,尝试访问 /actuator/routes 也会返回 404。

任何帮助将不胜感激,如果以上内容还不够,可以提供更多信息。

【问题讨论】:

  • 当我没有@EnableZuulProxy 时,我得到了那个确切的错误。否则,一个相同的应用程序对我来说很好。你能分享一个可下载的样本吗?执行器不会工作,因为它不是依赖项。

标签: spring-boot spring-cloud netflix-zuul


【解决方案1】:

Zuul 在您的应用中的行为很奇怪,您是否遗漏了一些可能来自其他位置的配置(例如 zuul.prefix server.prefix...)?

查看您的配置: zuul: routes: invoicing: path: /invoicing/** url: [url that I know works]/invoicing

这意味着来自zuul-server/invoicing/** 的所有调用都应该路由到[back-server-url]/invoicing/**,所以在你的输出中[zuul-server]/invoicing/v1/invoice/7900007809 应该路由到[back-server-url]/invoicing/v1/invoice/7900007809 但是使用not find handler method,这是否意味着[back-server-url]/invoicing/v1/invoice/7900007809 不可用?

btw 1. 您可以在应用程序启动期间检查输出,它应该打印 zuul 和执行器设置的 url 映射,这对于调试相同的问题很有用。 2.spring-cloud-starter-netflix-zuul实际上有RibbonHystrix和Actuator默认依赖,actuator应该可以工作,你可以检查/actuator/health

【讨论】:

  • 嘿@Seven,感谢您的评论。似乎这与 Zuul 实际上没有完全存在有关,因为我的本地 repo 缓存中有一些糟糕的 maven jar。感谢收看!
【解决方案2】:

好的,所以,我找到了答案。出于某种原因,我的 MVN 构建下载了一组伪造的 Zuul jar,在执行“清理”时给了我一些糟糕的 LOC 标头错误。擦除了我的本地 maven repo 缓存并重新构建,现在一切正常。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-05-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-19
    • 2015-11-11
    • 1970-01-01
    相关资源
    最近更新 更多