【 개발 이야기 】

[Spring Boot] WebFilter

홍호나 2025. 6. 19. 18:14

In Spring WebFlux, a WebFilter is an interface used to intercept and process web requests and responses in a reactive manner. It provides a mechanism for implementing cross-cutting concerns, such as security, logging, or request/response manipulation, before the request reaches the target handler or after the handler has processed it.

 

  • Interface Definition: The WebFilter interface defines a single method:
    public interface WebFilter {
        Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain);
    }
  • ServerWebExchange: Represents the HTTP request-response interaction, providing access to the ServerHttpRequest and ServerHttpResponse, along with other server-side properties.
     
  • WebFilterChain: Allows the filter to delegate to the next filter in the chain or to the actual request handler.