spring-projects / spring-framework

Spring Framework
https://spring.io/projects/spring-framework
Apache License 2.0
55.39k stars 37.67k forks source link

Add `@Router` and `@Handler` #32764

Closed earlgrey02 closed 3 weeks ago

earlgrey02 commented 3 weeks ago

Summary

Added @Router and @Handler to reference routers and handlers in functional endpoints.

Description

In general, annotation-based controller allows you to refer to controllers with unique annotations such as @Controller, while functional endpoint refers to routers and handlers with the traditional @Configuration and @Component annotations. I felt there was a need for annotations to uniquely refer to routers and handlers more explicitly( Whether used simply for writing explicit code or for AOP), so I posted this PR.

Example

@Router
class TestRouter {
    @Bean
    fun testRoutes(handler: TestHandler): RouterFunction<ServerResponse> =
        router {
            ...
        }
}
@Handler
class TestHandler {
    ....
}
snicoll commented 3 weeks ago

Thanks for the PR but we don’t intend to create first class annotations like suggested.

We prefer to provide a consistent way and let integrators create any specific stereotypes if needed.