org.springframework.cloud
spring-cloud-starter-netflix-eureka-client
确认Eureka服务注册中心已经成功启动并且正在监听请求。可以在Eureka服务器的日志中查看是否有类似于“Registered instance”的信息。
在Api-gateway的配置文件中添加Eureka服务注册中心的相关配置。可以在application.yml文件中添加如下配置:
eureka:
client:
service-url:
default-zone: http://eureka-server:8761/eureka/
其中,eureka-server表示Eureka服务注册中心的主机名,8761是Eureka服务注册中心的端口号。
@SpringBootApplication
@EnableDiscoveryClient
public class ApiGatewayApplication {
public static void main(String[] args) {
SpringApplication.run(ApiGatewayApplication.class, args);
}
}
注意:如果Eureka服务注册中心的安全验证被启用,还需要在Api-gateway配置文件中添加相关的认证信息。具体请参考Spring Cloud文档。