Allow registering custom filters and predicates in programmatic way (not spring.factories)
According to the documentation, if you want to use a custom filter for your route you have to publish a RouterFunction bean with the specified filter, with no alternatives if you want to configure the routing via properties. By contrast, in the reactive version of gateway you can publish a GatewayFilterFactory and reference the filter in your properties. It would be useful to be able to do the same with HandlerFilterFunctions.
At the moment the only way to do this is to create a FilterSupplier for your filters and reference it in a spring.factories file. Registering the FilterSupplier as bean does not work, since GatewayMvcPropertiesBeanDefinitionRegistrar does not perform any bean resolution, instead it delegates to the FilterDiscoverer which in turns uses SpringFactoriesLoader.loadFactories. While this works fine, it's cumbersome and it would be greatly simplified if you could directly publish the filters.
Registering FilterSupplier or PredicateSupplier is currently only supported via spring.factories. A BeanDefinitionRegistrar happens very early in the spring IoC lifecycle and I don't know how to get all the information as a bean. What about classpath scanning like for openfeign or spring data?
https://docs.spring.io/spring-cloud-openfeign/reference/spring-cloud-openfeign.html#netflix-feign-starter
Requiring annotations or interface extensions is also fine by me. I just want to avoid writing a spring.factories, which is error prone due to the lack of type safety
Is it somehow possible to add Before/After filters via spring.factories? It seems the "out-of-the-box" filters from SCG-mvc are using a wrapper class which is registered as full filters, with just one-liners that call the Before/After filter. Could do that for mine as well like this, but a more convient way as we had in the reactive gateway would be more comfortable.
Could RouterFunctionHolderFactory implement FactoryBean<Object>? This can then implement BeanFactoryAware to get access to other beans such as those that implement FilterSupplier
@ciscoo maybe. I'd have to do some design before I start looking at this feature.
waiting for this to switch from webflux to MVC
any updates?
No, but it is something to do for this upcoming release in May
Please follow #3763