@SpringBootApplication
public class GatewayApplication {
@Bean
DiscoveryClientRouteDefinitionLocator discoveryRoutes(DiscoveryClient dc, DiscoveryLocatorProperties dlp) {
return new DiscoveryClientRouteDefinitionLocator(dc, dlp);
}
public static void main(String[] args) {
SpringApplication.run(GatewayApplication.class, args);
}
}
spring.application.name=gateway
server.port=8081
eureka.client.register-with-eureka=true
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.hcl.cnp</groupId>
<artifactId>gateway</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>gateway</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>Finchley.RELEASE</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<!--<dependency>-->
<!--<groupId>org.springframework.boot</groupId>-->
<!--<artifactId>spring-boot-starter-security</artifactId>-->
<!--</dependency>-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</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-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
让它发挥作用。您不需要添加下面的bean,删除它
@Bean
DiscoveryClientRouteDefinitionLocator discoveryRoutes(DiscoveryClient dc, DiscoveryLocatorProperties dlp) {
return new DiscoveryClientRouteDefinitionLocator(dc, dlp);
}
在application.properties中,添加这两行以启用发现客户端
spring.cloud.gateway.discovery.locator.enabled=true
spring.cloud.gateway.discovery.locator.lower-case-service-id=true
而且它应该能起作用!
我正在研究一个示例poc,我正在尝试集成Spring云api网关 在我的pom.xml中,我有 在我的应用程序中。yml我有 在我的主课上 我能够直接从它们各自的端口访问服务,但是当我试图从端口网关端口ie 9191访问api时,我得到 ***2022-09-08 16:23:34.644错误4128-[ctor-http-nio-3]a . w . r . e . abstracterrorwe
我有一个Spring Boot应用程序正在尝试使用Spring Cloud Gateway访问一些微服务。我使用的代码基于以下位置的说明: 基本上,我的应用程序复制了该站点上提供的代码,包括作者创建的两个测试微服务: 和 我的实际网关代码与作者的类似: package com . betterjavacode . API gateway demo . config; 不幸的是,当我运行此应用程序时
当我使用spring cloud gateway集成spring cloud sleuth时,我发现性能比单独使用spring cloud gateway慢得多。是否有优化方案? 机器配置:6芯,16g Spring云网关:5331.9 tps Spring云网关Spring云侦探:4119.47 tps “Spring云网关”比“Spring云网关Spring云侦探”慢约1000-2000tps
我有一个带有一些endpoint的anexo API,比如: 如何将Spring Cloud Gateway与这些endpoint一起使用?
我正在尝试在Spring Cloud Gateway中启用RequestRateLimiter。我havr配置了其他过滤器,甚至是自定义过滤器,但当我将其添加到我的路由中时: 我得到了这个异常(当然,如果我移除RequestRateLimiter筛选器并只保留StripPrefix条目,一切正常。我已经删除了异常的代码):
我为所有传入请求创建了全局路由,并使用AbstracTerrorWebExceptionHandler。 我的application.yml 运行应用程序时的日志: 谢谢你的帮助。