如何让zuul和eureka一起使用动态路线?

b1zrtrql  于 2021-07-16  发布在  Java
关注(0)|答案(0)|浏览(296)

我试图让zuul和eureka一起工作,但当我试图将microservice的绝对(物理)路径更改为按microservice名称的相对路径时,我被卡住了。
我有下面显示的代码。
祖尔
应用程序.yml

  1. server:
  2. port: 8080
  3. management:
  4. endpoints:
  5. web:
  6. exposure:
  7. include: '*'
  8. spring:
  9. application:
  10. name: gateway
  11. zuul:
  12. prefix: /api
  13. routes:
  14. lesson-service:
  15. path: /lesson-service/**
  16. serviceId: lesson-service
  17. eureka:
  18. instance:
  19. preferIpAddress: true
  20. client:
  21. registerWithEureka: true
  22. fetchRegistry: true
  23. serviceUrl:
  24. defaultZone: ${EUREKA_URI:http://localhost:8761/eureka}

主要的

  1. @SpringBootApplication
  2. @EnableZuulProxy
  3. @EnableDiscoveryClient
  4. public class TeachmeGatewayApplication {
  5. public static void main(String[] args) {
  6. SpringApplication.run(TeachmeGatewayApplication.class, args);
  7. }
  8. }

Eureka
应用程序.yml

  1. server:
  2. port: 8761
  3. management:
  4. endpoints:
  5. web:
  6. exposure:
  7. include: '*'
  8. eureka:
  9. client:
  10. registerWithEureka: false
  11. fetchRegistry: false
  12. server:
  13. waitTimeInMsWhenSyncEmpty: 0

主要的

  1. @SpringBootApplication
  2. @EnableEurekaServer
  3. public class TechmeEurekaApplication {
  4. public static void main(String[] args) {
  5. SpringApplication.run(TechmeEurekaApplication.class, args);
  6. }
  7. }

课程服务
应用程序.yml

  1. server:
  2. port: 8081
  3. spring:
  4. application:
  5. name: lesson-service

主要的

  1. @SpringBootApplication
  2. @EnableDiscoveryClient
  3. public class TechmeLessonApplication {
  4. public static void main(String[] args) {
  5. SpringApplication.run(TechmeLessonApplication.class, args);
  6. }
  7. }

控制器

  1. @RestController
  2. public class LessonController {
  3. @GetMapping("/info")
  4. public String getInfo() {
  5. return "All is ok!";
  6. }
  7. }

当我试图从 http://localhost:8080/api/lesson-service/info url我得到了500http错误。

  1. Whitelabel Error Page
  2. This application has no explicit mapping for /error, so you are seeing this as a fallback.
  3. Sat Mar 20 12:38:40 OMST 2021
  4. There was an unexpected error (type=Internal Server Error, status=500).

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题