Overview

We can reduce the amount of generated proxy configuration and the native footprint by avoiding inclusion of unused annotation proxy classes in the native images.

Rationale

Annotations like @GetMapping in Spring MVC are composed annotations for @RequestMapping; however, there is nowhere in the core Spring Framework where a lookup is performed for a @GetMapping annotation. Rather, the corresponding lookups are only for merged @RequestMapping annotations.

Consequently, @RequestMapping needs to be synthesized, but the composed annotations @GetMapping, @PostMapping, etc. do not need to be synthesized.

In other words, WebAnnotationsRuntimeHintsRegistrar.registerHints() can be greatly simplified.

Brainstorming

We could analyze how we use RuntimeHintsUtils.registerAnnotation, simplify our usage by only registering annotations we know will need to be synthesized, and update the documentation to reflect this mindset/guidance.

We could introduce support (potentially in the agent) to detect the use of @AliasFor referencing a meta-annotation's attribute and automatically register the target meta-annotation for a synthesized annotation proxy.

Related Issues

  • 28767

Comment From: snicoll

RuntimeHintsUtils has now a registerComposableAnnotation, so I think using it on RequestMapping should cover some ground. The brainstorming bit in this issue makes it harder for me to understand the scope it.

Comment From: snicoll

@sbrannen can we please clarify the scope of this?

Comment From: sbrannen

RuntimeHintsUtils has now a registerComposableAnnotation, so I think using it on RequestMapping should cover some ground.

Yes, that should help.

My original concern was that we generate too many hints for SynthesizedAnnotation proxies for certain sets of annotations -- for example, @GetMapping, etc. in WebAnnotationsRuntimeHintsRegistrar. See also #28953.

We should now be using registerComposableAnnotation for @RequestMapping, and for @GetMapping, etc. we would need a new method that only registers the reflection hints for @GetMapping. In other words, if we supply GetMapping.class to RuntimeHintsUtils.registerAnnotation, it will register a SynthesizedAnnotation proxy hint for @GetMapping that will never be used within a native image (or at least not as a result of standard usage in the framework itself).

So, we could consider introducing a method such as RuntimeHintsUtils.registerAnnotationForReflectionOnly.

The brainstorming bit in this issue makes it harder for me to understand the scope it.

I've covered part of the brainstorming above regarding the introduction of another "for reflection only" registration method.

The second part is to document specific use cases in the Javadoc to make it clear to the user when to use which registerAnnotation* variant. @RequestMapping and @GetMapping serve as a prime example that we can discuss to clarify things for users.

The last part was about automating the process of invoking registerAnnotation* variants in an agent that performs static analysis to determine the appropriate action instead of leaving it up to the user. This part is of course totally optional and could be added later down the road if deemed desirable.

Does that make sense now?

Comment From: snicoll

I am not 100% sure but it looks like this issue, as described, is supesrseded now

Comment From: sbrannen

Indeed it may be superseded now. I'll take another pass later in the week.

Comment From: sbrannen

Closing in light of #28967 and related recent changes.

If the need arises, we can reopen this issue at a later date.