简体   繁体   English

Spring Cloud Gateway - 无法找到名称为 [Filter_Name] 的 GatewayFilterFactory

[英]Spring Cloud Gateway - Unable to find GatewayFilterFactory with name [Filter_Name]

I have a spring cloud gateway application.我有一个 spring 云网关应用程序。 I am trying to setup a gateway filter.我正在尝试设置网关过滤器。 The Spring Boot version is 2.3.4.RELEASE Here are the dependencies: Spring Boot 版本是2.3.4.RELEASE这里是依赖:

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter'
    implementation platform(SpringBootPlugin.BOM_COORDINATES)
    implementation platform('org.springframework.cloud:spring-cloud-dependencies:Hoxton.SR8')
    implementation 'org.springframework.boot:spring-boot-starter-actuator'
    implementation 'org.springframework.cloud:spring-cloud-starter-gateway'
    implementation 'org.springframework.cloud:spring-cloud-starter-sleuth'
    implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'

}

Here is the configutraion for the gateway client这是网关客户端的配置

server:
  port: 8081
spring:
  cloud:
    gateway:
      routes:
        - id: onboard_redirect
          uri: http://localhost:8080/api/v1/onboard
          predicates:
            - Path=/api/v1/onboard
          filters:
            - name: MyLogging
              args:
                baseMessage: My Custom Message
                preLogger: true
                postLogger: true

Here is my filter class:这是我的过滤器类:

@Component
public class MyLoggingGatewayFilterFactory extends AbstractGatewayFilterFactory<MyLoggingGatewayFilterFactory.Config> {

    final Logger logger =
            LoggerFactory.getLogger(MyLoggingGatewayFilterFactory.class);

    public MyLoggingGatewayFilterFactory() {
        super(Config.class);
    }

    @Override
    public GatewayFilter apply(Config config) {
        return (exchange, chain) -> {
            // Pre-processing
            if (config.preLogger) {
                logger.info("Pre GatewayFilter logging: "
                        + config.baseMessage);
            }
            return chain.filter(exchange)
                    .then(Mono.fromRunnable(() -> {
                        // Post-processing
                        if (config.postLogger) {
                            logger.info("Post GatewayFilter logging: "
                                    + config.baseMessage);
                        }
                    }));
        };
    }

    public static class Config {
        public String baseMessage;
        public boolean preLogger;
        public boolean postLogger;
    }
}

Everything works without configuring the filter but when I configure the filter I get follwing error:一切正常,无需配置过滤器,但是当我配置过滤器时,出现以下错误:

reactor.core.Exceptions$ErrorCallbackNotImplemented: java.lang.IllegalArgumentException: Unable to find GatewayFilterFactory with name MyLogging
Caused by: java.lang.IllegalArgumentException: Unable to find GatewayFilterFactory with name MyLogging

what I am doing wrong here?我在这里做错了什么?

The filter class is MyLoggingGatewayFilterFactory , not MyLogging as you set in your properties.过滤器类是MyLoggingGatewayFilterFactory ,而不是您在属性中设置的MyLogging

Try to the following modification in your application.yml file:尝试在application.yml文件中进行以下修改:

filters:
    - name: MyLoggingGatewayFilterFactory

Add this dependency in the application.properties file.在 application.properties 文件中添加此依赖项。

<dependency>
       <groupId>org.springframework.cloud</groupId>
       <artifactId>spring-cloud-starter-circuitbreaker-reactor- 
     resilience4j</artifactId>
</dependency>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring Cloud Gateway 启动失败:无法找到具有名称的 GatewayFilterFactory<blank> - Spring Cloud Gateway Failed to start: Unable to find GatewayFilterFactory with name <blank> Spring 云 API 网关:Resilience4j:找不到名称为 CircuitBreaker 的 GatewayFilterFactory - Spring Cloud API Gateway : Resilience4j : Unable to find GatewayFilterFactory with name CircuitBreaker Spring引导网关错误-无法找到带有名称路径的RoutePredicateFactory - Spring boot gateway error - Unable to find RoutePredicateFactory with name path Spring 网关应用程序找不到自定义过滤器 - Spring gateway application unable to find custom filter Spring 引导 API 网关无法解析名称 - Spring Boot API Gateway Unable to resolve name Spring Cloud Gateway 和 TokenRelay 过滤器 - Spring Cloud Gateway and TokenRelay Filter Spring 云网关自定义网关过滤器不工作 - Spring Cloud Gateway Custom Gateway Filter Not Working 具有SSL的Spring Cloud Gateway无法按名称路由到服务 - Spring Cloud Gateway with SSL cannot route to service by name Spring Cloud 网关在过滤器中发送响应 - Spring Cloud gateway send response in filter Spring cloud sleuth ExtraFieldPropagation在Spring cloud Gateway Filter中失败 - Spring cloud sleuth ExtraFieldPropagation fail in Spring cloud Gateway Filter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM