[英]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.