Netflix Zuul服务器-/ routes端点不可用

时间:2018-09-19 09:29:36

标签: java microservices spring-cloud netflix-zuul spring-cloud-netflix

在此学习微服务的编码练习中,我创建了一个Netflix Zuul项目,用于对微服务进行服务路由。

可悲的是,/ routes端点似乎没有被挂载。一切似乎都正常:定义前缀并为我的服务设置特定的路由。

zuul服务器日志文件没有错误。 当我尝试在邮递员上访问/ routes网址时,出现404错误: Zuul Routes not returning anything

我的Zuul应用程序类:

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

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

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/maven-v4_0_0.xsd">

    <modelVersion>4.0.0</modelVersion> <!--should be set to 4.0.0 -->
    <groupId>com.booking.system.hotel</groupId>
    <version>0.0.1-SNAPSHOT</version>
    <artifactId>hotel-gateway-service-server</artifactId>

    <name>Hotel Gateway service - zuul</name>
    <description>Hotel Gateway service - it uses Netflix Zuul Proxy Server</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.5.RELEASE</version>
    </parent>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Finchley.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
        <start-class>com.booking.system.hotel.zuulsvr.ZuulServerApplication</start-class>
    </properties>
    <dependencies>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-zuul</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-config-client</artifactId>
        </dependency>
    </dependencies>

    <build>
    <finalName>hotel-gateway-service-server</finalName> <!--name of the jar -->
        <plugins>
            <!-- packages the project as an executable jar, as an Spring Boot application -->
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <!-- used for running tests at various stages -->
        </plugins>
    </build>
</project>

bootstrap.yml文件:

spring:
  application:
    name: hotel-gateway-service-server
  profiles:
    active:
      default
  cloud:
    config:
      enabled: true

来自配置服务器的Zuul配置文件:

zuul.ignored-services: "*"
zuul.prefix:  /api
zuul.routes.hotel-reservations-service: /reservations/**
zuul.routes.hotel-rooms-service: /rooms/**

docker-compose.yml条目,用于初始化zuul网关服务器:

   hotel-gateway-service-server: #zuul server
      image: imageprefix/hotel-gateway-service-server
      ports:
         - 5555:5555
      environment:
         PROFILE: "dev"
         SERVER_PORT: "5555" 
         CONFIGSERVER_URI: "http://hotel-configuration-server:8888"
         CONFIGSERVER_PORT: "8888"
         EUREKASERVER_URI: "http://hotel-service-discovery-server:8761/eureka/"
         EUREKASERVER_PORT: "8761"

我似乎没有发现我所缺少的东西。

1 个答案:

答案 0 :(得分:5)

执行器基本路径具有changed/actuator。因此,您需要使用/actuator/routes。默认情况下也未启用。

management.endpoints.web.exposure.include=*