What is the difference between Router and Annotated Controllers?

If we leave individual preference, there is one explicit difference in filters.

The WebFlux framework provides two types of filters: WebFilters and HandlerFilterFunctions.

The main difference between them is that WebFilter implementations work for all endpoints and HandlerFilterFunction implementations will only work for Router-based ones.


Let me start with your last question

Is 2 better than 1, in performance?

No, there is no difference in the performance.

I find that 2 is harder to use than 1

That is absolutely based on individual preference. May be you are used to imperative style of programming. And hence you feel it easy to write(Trust me after a while you would feel the same with Router Functions as well)

Basically Router Functions are one step towards functional style of programming. Spring wanted users to have the flexibility to configure routes in functional style.
Apart from this there is no difference between Controllers and Router Functions.


The RouterFunction has a similar purpose as the annotation. However, there is an important distinction: with the annotation, your route is limited to what can be expressed through the annotation values.