-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Provide better DevXP for missing reflection hints where inference is not possible #28979
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
Comments
We're recently extracted the logic of processing
A possible annotation reusing our infrastucture could be: @Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Reflective(RegisterReflectionProcessor.class)
public @interface RegisterReflection {
Class<?>[] value();
// Other fields
}
We could have as "many" annotations and processors as we want to. |
Move it to org.springframework.aot.hint. See spring-projectsgh-28979
The purpose of this issue is to provide a reasonable developer experience for missing reflection hints on types invisible to Spring AOT runtime hints inference. Typical use case is usage of reflection-based libraries in the implementation without exposing related types in methods APIs.
Use cases
Jackson
A popular example is serialization/deserialization with like Jackson, either directly invoked via
objectMapper.readValue(json, POJO.class)
or most often viaWebClient
/RestTemplate
. Unlike with@RequestMapping
return values, Spring AOT processing has no way to infer this. That means a developer will have to create aRuntimeHintsRegistrar
implementation that will leverageBindingReflectionHintsRegistrar
like here and to declare it on a bean with@ImportRuntimeHints
. It works but it is painful and verbose.Quartz
Another example is Quartz jobs, declared in spring-aot-smoke-tests as following:
The current solution is to create a
RuntimeHintsRegistrar
implementation and to declare it on a bean with@ImportRuntimeHints
which is also pretty verbose.Spring Native
In Spring Native, this kind of use case was handled by annotating a bean with for example
@TypeHint(types = Data.class, access = { TypeAccess.DECLARED_CONSTRUCTORS, TypeAccess.PUBLIC_METHODS })
, but this was pretty hard to get it right when the reflection-based serialization required entries for multiple classes (typically the non-trivial logic implemented in SF6BindingReflectionHintsRegistrar
).Notice there are a bunch of
FailureAnalyzer
that take this assumption that on native a missing reflection entry is likely related to missing native configuration, so the error message guide the user to try to add the right one.The ideal fix for this issue was discussed in spring-attic/spring-native#1152 but what is proposed here sounds not realistic for Spring Framework 6 GA, so we need a more pragmatic solution.
Proposal
We could maybe introduce an annotation applied typically at bean class level that would allow the user to specify that a want reflection hints for a specific type or types specified by
Class
orString
. It could applyBindingReflectionHintsRegistrar
logic (reflection on all types recursively used in the type hierarchy for setters, getters, record methods and fields) on the specified types:Side notes:
@ReflectionHintsForTypeHierarchy
welcomed if you have better ideasBindingReflectionHintsRegistrar
(TypeHierarchyReflectionHintsRegistrar
?) to be consistent with this annotation and have a more generic name. "Binding" was chosen because it was less confusing than "Serialization" which can apply to both Java serialization and reflection-based serialization.@Reflective
?The text was updated successfully, but these errors were encountered: