带有Netflix Zuul的Spring Boot 2无法正常工作吗?

时间:2018-09-17 16:57:29

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

我有一个非常简单的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 / [一些要通过的东西]之类的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。

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

2 个答案:

答案 0 :(得分:0)

奇怪的是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实际上具有默认的Ribbon HystrixActuator依赖性,actuator应该可以工作,您可以检查/actuator/health

答案 1 :(得分:0)

好的,所以我找到了答案。由于某种原因,我的MVN版本已下载了一组伪造的Zuul罐子,这在执行“清理”操作时给了我一些不良的LOC标头错误。擦除了我的本地Maven回购缓存并重新构建,现在一切正常。