Class CorsGatewayFilterApplicationListener
- All Implemented Interfaces:
EventListener, org.springframework.context.ApplicationListener<RefreshRoutesResultEvent>
For each Route, this listener inspects its predicates and looks for an instance
of PathRoutePredicateFactory. If a path predicate is found, the first defined
path pattern is extracted and used as the key for associating the route-specific
CorsConfiguration.
After collecting all route-level CORS configurations, the listener merges them with
globally defined configurations from GlobalCorsProperties, ensuring that
route-specific configurations take precedence over global ones in case of conflicts
(e.g., both defining CORS rules for /**).
The merged configuration map is then applied to the
RoutePredicateHandlerMapping via setCorsConfigurations.
Note: A LinkedHashMap is used to store the merged configurations to preserve
insertion order, which ensures predictable CORS resolution when multiple path patterns
could match a request.
- Author:
- Fredrich Ombico, Abel Salgado Romero, Yavor Chamov
-
Constructor Summary
ConstructorsConstructorDescriptionCorsGatewayFilterApplicationListener(GlobalCorsProperties globalCorsProperties, RoutePredicateHandlerMapping routePredicateHandlerMapping, RouteLocator routeLocator) -
Method Summary
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.context.ApplicationListener
supportsAsyncExecution
-
Constructor Details
-
CorsGatewayFilterApplicationListener
public CorsGatewayFilterApplicationListener(GlobalCorsProperties globalCorsProperties, RoutePredicateHandlerMapping routePredicateHandlerMapping, RouteLocator routeLocator)
-
-
Method Details
-
onApplicationEvent
- Specified by:
onApplicationEventin interfaceorg.springframework.context.ApplicationListener<RefreshRoutesResultEvent>
-