zuulproxy在spring启动应用程序中不起作用

mbyulnm0  于 2021-07-11  发布在  Java
关注(0)|答案(1)|浏览(475)

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

类servicesinfoclient是一个微服务,其配置文件是serviceinfo.yml。
serviceinfoclient.java:

  1. package com.myoldschool.manager.serviceClientInfo;
  2. import com.myoldschool.manager.studentnames.StudentNameCountClient;
  3. import org.springframework.boot.SpringApplication;
  4. import org.springframework.boot.autoconfigure.SpringBootApplication;
  5. import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
  6. import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
  7. import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
  8. import org.springframework.cloud.openfeign.EnableFeignClients;
  9. import org.springframework.web.bind.annotation.GetMapping;
  10. import org.springframework.web.bind.annotation.RestController;
  11. @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class })
  12. @EnableDiscoveryClient
  13. @RestController
  14. public class ServicesInfoClient {
  15. public static void main(String[] args) {
  16. System.setProperty("spring.config.name", "serviceInfo");
  17. SpringApplication.run(StudentNameCountClient.class, args);
  18. }
  19. @GetMapping("/getInfo")
  20. public String getServiceEndPoints(){
  21. return "all endpoints";
  22. }
  23. }

服务信息.yml:

  1. # Discovery Server Access
  2. spring:
  3. application:
  4. name: services-info
  5. eureka:
  6. client:
  7. registerWithEureka: true
  8. fetchRegistry: true
  9. serviceUrl:
  10. defaultZone: http://localhost:1111/eureka/
  11. instance:
  12. hostname: localhost
  13. # HTTP Server
  14. server:
  15. port: 4444 # HTTP (Tomcat) port

myzuulproxyclient.java文件:

  1. package com.myoldschool.manager.zuulservice;
  2. import com.myoldschool.manager.ManagerApplication;
  3. import org.springframework.boot.SpringApplication;
  4. import org.springframework.boot.autoconfigure.SpringBootApplication;
  5. import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
  6. import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
  7. import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
  8. @EnableZuulProxy
  9. @EnableDiscoveryClient
  10. @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class })
  11. public class MyZuulProxyClient {
  12. public static void main(String[] args) {
  13. System.setProperty("spring.config.name", "zuulService");
  14. SpringApplication.run(ManagerApplication.class, args);
  15. }
  16. }

zuulservice.yml网址:

  1. # Configure this Discovery Server
  2. spring:
  3. application:
  4. name: zuul-service
  5. eureka:
  6. client:
  7. registerWithEureka: false
  8. fetchRegistry: true
  9. serviceUrl:
  10. defaultZone: http://localhost:1111/eureka/
  11. instance:
  12. hostname: localhost
  13. # HTTP Server
  14. server:
  15. port: 5555 # HTTP (Tomcat) port
  16. zuul:
  17. routes:
  18. services-info:
  19. path: /services-info/**
  20. serviceId: services-info

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

  1. Whitelabel Error Page
  2. This application has no explicit mapping for /error, so you are seeing this as a fallback.
  3. Sun Nov 22 16:34:12 IST 2020
  4. There was an unexpected error (type=Not Found, status=404).

我见过这么多线程,但没有一个是工作的。所以请告诉我我做错了什么。

irtuqstp

irtuqstp1#

我看不到你的eurekaserver微服务。您需要将eureka服务器创建为port:1111. 之后,您的微服务可以注册它。

相关问题