[英]ZuulProxy is not working in spring boot application
我創建了一個 spring boot 應用程序,它有一個微服務。 現在我想從我在 eureka 服務器上注冊的瀏覽器直接訪問該微服務。
類ServicesInfoClient是一種微服務,它的配置文件是serviceInfo.yml 。
服務信息客戶端.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";
}
}
服務信息.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).
我見過很多線程,但沒有一個有效。 所以請告訴我我在這里做錯了什么。
我看不到你的 EurekaServer 微服務。 您需要將 Eureka 服務器創建為端口:1111。 之后,您的微服務可以注冊它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.