spring-cloud - 我们可以在同一个 SpringBootApplication 上配置 spring 云网关和服务发现(eureka 服务器)吗
问题描述
我正在尝试在同一个@SpringBootApplication 上运行 Spring Cloud“Gateway”和“Eureka-Server”,下面是我的代码:
主类:
@SpringBootApplication
@EnableEurekaServer
@EnableAdminServer
public class DemoGatewayApplication {
public static void main(String[] args) {
SpringApplication.run(DemoGatewayApplication .class, args);
}
}
pom.xml
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency>
</dependencies>
应用程序.yml
server:
port: ${GATEWAY_SERVER_PORT:8080}
eureka:
instance:
hostname: localhost
appname: ${spring.application.name}
client:
enabled: true
healthcheck:
enabled: true
fetch-registry: true
register-with-eureka: true
instance-info-replication-interval-seconds: 10
registry-fetch-interval-seconds: 10
service-url:
defaultZone: http://${REGISTRY_SERVER_IP:localhost}:${REGISTRY_SERVER_PORT:8080}/eureka
当我运行此应用程序时,我收到如下错误。我不确定是什么问题,或者是否可以在同一实例上拥有网关和 eureka 服务器?
2021-09-13 18:10:12.411 INFO [gateway-service,,] 224 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_GATEWAY-SERVICE/gateway-service:9fd20bce350b1ccb477d53ad05e3504f - registration status: 404
2021-09-13 18:10:12.831 INFO [gateway-service,,] 224 --- [ main] o.s.cloud.commons.util.InetUtils : Cannot determine local hostname
2021-09-13 18:10:13.979 INFO [gateway-service,,] 224 --- [ main] o.s.cloud.commons.util.InetUtils : Cannot determine local hostname
2021-09-13 18:10:14.056 INFO [gateway-service,,] 224 --- [ main] c.n.gateway.DemoGatewayApplication : Started DemoGatewayApplication in 27.56 seconds (JVM running for 29.713)
2021-09-13 18:10:15.459 INFO [gateway-service,,] 224 --- [tbeatExecutor-0] c.n.d.s.t.d.RedirectingEurekaHttpClient : Request execution error. endpoint=DefaultEndpoint{ serviceUrl='http://localhost:8080/eureka/}
解决方案
推荐阅读
- https - 为 Asp.net core web api 启用 HTTPS 安全连接
- e4 - 构建 RCP 应用程序没有运行生命周期管理器
- python - Python:在不同长度的视频中提取“n”帧
- selenium - Selenium - IE 驱动程序:单击 js 中定义的链接,_blank 什么都不做
- excel - Excel:在不同列上排序时如何将单元格保持在一起
- javascript - 受控/非受控输入
- asp.net-mvc - 通过 EF6 和 LINQ 从 Oracle DB 接收相关实体
- html - Bind service property to a controller AngularJS
- excel - CK13N 事务使用 VBA 从 GuiTree 表字段中读取文本
- android - 加密存储在 Firebase 数据库中的聊天消息