Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reflection hints for Web controllers #28518

Closed
snicoll opened this issue May 24, 2022 · 4 comments
Closed

Add reflection hints for Web controllers #28518

snicoll opened this issue May 24, 2022 · 4 comments
Assignees
Labels
theme: aot An issue related to Ahead-of-time processing type: enhancement A general enhancement
Milestone

Comments

@snicoll
Copy link
Member

snicoll commented May 24, 2022

The core framework invokes @RequestMapping-annotated methods (@GetMapping, etc) using reflection. To run in a native image, we need hints for those. We may also want to infer that return types are going to be serialized, or that input times are going to be mapped from the request.

All this can go away if we generate an optimized code for the router but let's go the hints route for now.

@snicoll snicoll added type: enhancement A general enhancement theme: aot An issue related to Ahead-of-time processing labels May 24, 2022
@snicoll snicoll added this to the 6.0.0-M5 milestone May 24, 2022
@snicoll
Copy link
Member Author

snicoll commented May 24, 2022

For the annotations themselves and loading org/springframework/http/mime.types it would be nice if those were contributed only if the application is going to use it. Adding a RuntimeHintsRegistrar in aot.factories would not achieve that goal but it's not clear cut where to put @ImportRuntimeHints. As it should be consistent, we can't really rely on Spring Boot for that.

For the annotations, I was tempted to add an import on org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping but it's not obvious that's going to be a bean so the annotation there feels a little bit odd.

@snicoll
Copy link
Member Author

snicoll commented May 24, 2022

Considering that MergedAnnotations is required to automatically handle the creation of the proxy. I wonder if dealing with everything that is method specific can be a good thing. This would be more code but more tailored to what is actually happening in the application.

@sdeleuze
Copy link
Contributor

sdeleuze commented Jun 8, 2022

I managed to make webmvc-tomcat sample working with https://github.com/sdeleuze/spring-framework/tree/gh-28518. I will refine it based on @snicoll feedback.

@sdeleuze
Copy link
Contributor

This issue will be focused on reflection hints for controllers and reflection-based serialization of parameters annotated
with @RequestBody and return values annotated with @ResponseBody. I will create subsequent issues for other use-cases (HttpEntity, @ControllerAdvice, etc.)

sdeleuze pushed a commit to sdeleuze/spring-framework that referenced this issue Jun 13, 2022
sdeleuze added a commit to sdeleuze/spring-framework that referenced this issue Jun 13, 2022
sdeleuze added a commit to sdeleuze/spring-framework that referenced this issue Jun 13, 2022
Add support for processing implemented interfaces and
remove Reflective from runtime hints.

See spring-projectsgh-28518
sdeleuze added a commit to sdeleuze/spring-framework that referenced this issue Jun 13, 2022
Support reflection-based serialization of parameters annotated
with @RequestBody and return values annotated with @responsebody.

It leverages a new BindingReflectionHintsRegistrar class that
is designed to register transitively the types usually needed
for binding and reflection-based serialization on fields,
constructors and properties Generics are taken in account as
well.

Closes spring-projectsgh-28518
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme: aot An issue related to Ahead-of-time processing type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants