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

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

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

server:
  port: 8080
management:
  endpoints:
    web:
      exposure:
        include: '*'
spring:
  application:
    name: gateway
zuul:
  prefix: /api
  routes:
    lesson-service:
      path: /lesson-service/**
      serviceId: lesson-service
eureka:
  instance:
    preferIpAddress: true
  client:
    registerWithEureka: true
    fetchRegistry: true
    serviceUrl:
      defaultZone: ${EUREKA_URI:http://localhost:8761/eureka}

主要的

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

Eureka
应用程序.yml

server:
  port: 8761
management:
  endpoints:
    web:
      exposure:
        include: '*'
eureka:
  client:
    registerWithEureka: false
    fetchRegistry: false
    server:
      waitTimeInMsWhenSyncEmpty: 0

主要的

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

课程服务
应用程序.yml

server:
  port: 8081
spring:
  application:
    name: lesson-service

主要的

@SpringBootApplication
@EnableDiscoveryClient
public class TechmeLessonApplication {

    public static void main(String[] args) {
        SpringApplication.run(TechmeLessonApplication.class, args);
    }

}

控制器

@RestController
public class LessonController {

    @GetMapping("/info")
    public String getInfo() {
        return "All is ok!";
    }
}

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

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

Sat Mar 20 12:38:40 OMST 2021
There was an unexpected error (type=Internal Server Error, status=500).

暂无答案!

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

相关问题