【问题标题】:ZuulProxy is not working in spring boot applicationZuulProxy 在 Spring Boot 应用程序中不起作用
【发布时间】:2020-11-22 11:05:47
【问题描述】:

我创建了一个 Spring Boot 应用程序,它有一个微服务。现在我想直接从我在 eureka 服务器上注册的浏览器访问那个微服务。

ServicesInfoClient类是一个微服务,其配置文件是serviceInfo.yml

ServiceInfoClient.java:

package com.myoldschool.manager.serviceClientInfo;

import com.myoldschool.manager.studentnames.StudentNameCountClient;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class })
@EnableDiscoveryClient
@RestController
public class ServicesInfoClient {

    public static void main(String[] args) {
        System.setProperty("spring.config.name", "serviceInfo");
        SpringApplication.run(StudentNameCountClient.class, args);
    }

    @GetMapping("/getInfo")
    public String getServiceEndPoints(){
        return "all endpoints";
    }

}

serviceInfo.yml:

# Discovery Server Access
spring:
  application:
    name: services-info

eureka:
  client:
    registerWithEureka: true
    fetchRegistry: true
    serviceUrl:
      defaultZone: http://localhost:1111/eureka/
    instance:
      hostname: localhost

# HTTP Server
server:
  port: 4444   # HTTP (Tomcat) port

MyZuulProxyClient.java:

package com.myoldschool.manager.zuulservice;

import com.myoldschool.manager.ManagerApplication;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;

@EnableZuulProxy
@EnableDiscoveryClient
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class })
public class MyZuulProxyClient {

    public static void main(String[] args) {
        System.setProperty("spring.config.name", "zuulService");
        SpringApplication.run(ManagerApplication.class, args);
    }
}

zuulService.yml:

# Configure this Discovery Server
spring:
  application:
    name: zuul-service

eureka:
  client:
    registerWithEureka: false
    fetchRegistry: true
    serviceUrl:
      defaultZone: http://localhost:1111/eureka/
    instance:
      hostname: localhost

# HTTP Server
server:
  port: 5555   # HTTP (Tomcat) port

zuul:
  routes:
    services-info:
      path: /services-info/**
      serviceId: services-info

现在运行应用程序后,当我点击http://localhost:1111/services-info/getInfo 时,它给了我这个错误:

Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.

Sun Nov 22 16:34:12 IST 2020
There was an unexpected error (type=Not Found, status=404).

我见过这么多线程,但没有一个有效。所以请告诉我我在这里做错了什么。

【问题讨论】:

    标签: java spring-boot netflix-eureka netflix-zuul


    【解决方案1】:

    我看不到你的 EurekaServer 微服务。您需要将 Eureka Server 创建为端口:1111。之后,你的微服务就可以注册它了。

    【讨论】:

    • 我刚刚没有在这里发布它的代码,但我确实有它,你可以在我的问题的第二行中轻松阅读到“我已在尤里卡服务器注册的浏览器中的微服务”。跨度>
    • 您的请求发送到 Eureka Server,端口为 1111。但是,您应该将请求发送到您的 ZuulProxy。 ZuulProxy 会找到你的路径并将请求转发到相关的微服务。请使用 5555 编辑端口。localhost:5555/services-info/getInfo.
    猜你喜欢
    • 2018-03-15
    • 2021-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多