我正在尝试使 zuul 和 eureka 一起工作,但是当我尝试通过微服务名称将微服务的绝对(物理)路径更改为相对路径时,我被卡住了。
我有下面显示的代码。
祖尔
应用程序.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);
}
}
尤里卡
应用程序.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 获得响应时,我收到 500 http 错误。
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).