Say*_*tan 5 spring-boot spring-cloud netflix-eureka netflix-zuul
我试图让一个简单的微服务注册到Eureka服务器,然后让Zuul代理到微服务.我得到微服务注册到Eureka服务器.但是,每当我带上Zuul服务时,我都会看到它没有注册到Eureka服务器.每当我尝试路由到微服务时,我得到以下异常:
负载均衡器没有可用于客户端的服务器:microservice
我无法弄清问题在哪里.任何帮助将不胜感激
下面是我对每个组件的Spring Boot类.
微服务组件
MicroserviceApplication.java
@SpringBootApplication(scanBasePackages = { "some.package.controller", "some.package.service" })
@EnableEurekaClient
@EnableJpaRepositories("some.package.repository")
@EntityScan("some.package.entity")
public class MicroserviceApplication {
public static void main(String[] args) {
SpringApplication.run(MicroserviceApplication.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
bootstrap.yml
server:
port: 8090
info:
component: Core Services
spring:
application:
name: microservice
Run Code Online (Sandbox Code Playgroud)
application.yml
eureka:
instance:
leaseRenewalIntervalInSeconds: 1
leaseExpirationDurationInSeconds: 2
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
healthcheck:
enabled: true
lease:
duration: 5
#some other logging and jpa properties below
Run Code Online (Sandbox Code Playgroud)
Eureka服务器组件
EurekaServerApplication.java
@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaServerApplication.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
bootstrap.yml
spring:
application:
name: discovery-server
Run Code Online (Sandbox Code Playgroud)
application.yml
server:
port: 8761
info:
component: Discovery Server
eureka:
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
instance:
hostname: localhost
server:
waitTimeInMsWhenSyncEmpty: 0
Run Code Online (Sandbox Code Playgroud)
API网关组件
ZuulGatewayApplication.java
@SpringBootApplication
@EnableZuulProxy
public class ZuulGatewayApplication {
public static void main(String[] args) {
SpringApplication.run(ZuulGatewayApplication.class, args);
}
@Bean
public ZuulGatewayPreFilter gatewayPreFilter() {
return new ZuulGatewayPreFilter();
}
}
Run Code Online (Sandbox Code Playgroud)
bootstrap.yml
spring:
application:
name: api-gateway
Run Code Online (Sandbox Code Playgroud)
application.yml
server:
port: 8888
info:
component: API Gateway
eureka:
instance:
leaseRenewalIntervalInSeconds: 1
leaseExpirationDurationInSeconds: 2
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
zuul:
routes:
microservice:
path: /microservice/**
serviceId: microservice
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12130 次 |
| 最近记录: |