Annotation Interface ImportRuntimeHints


@Target({TYPE,METHOD}) @Retention(RUNTIME) @Documented public @interface ImportRuntimeHints
Indicates that one or more RuntimeHintsRegistrar implementations should be processed.

Unlike declaring RuntimeHintsRegistrar using META-INF/spring/aot.factories, this annotation allows for more flexible registration where it is only processed if the annotated component or bean method is actually registered in the bean factory. To illustrate this behavior, consider the following example:

 @Configuration
 public class MyConfiguration {

     @Bean
     @ImportRuntimeHints(MyHints.class)
     @Conditional(MyCondition.class)
     public MyService myService() {
         return new MyService();
     }
 }

If the configuration class above is processed, MyHints will be contributed only if MyCondition matches. If the condition does not match, MyService will not be defined as a bean and the hints will not be processed either.

@ImportRuntimeHints can also be applied to any test class that uses the Spring TestContext Framework to load an ApplicationContext.

If several components or test classes refer to the same RuntimeHintsRegistrar implementation, the registrar will only be invoked once for the given bean factory processing or test suite.

Since:
6.0
Author:
Brian Clozel, Stephane Nicoll
See Also:
  • RuntimeHints
  • Reflective
  • RegisterReflectionForBinding
  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    Class<? extends org.springframework.aot.hint.RuntimeHintsRegistrar>[]
    RuntimeHintsRegistrar implementations to process.
  • Element Details

    • value

      Class<? extends org.springframework.aot.hint.RuntimeHintsRegistrar>[] value
      RuntimeHintsRegistrar implementations to process.