Interface RuntimeBeanDefinition<T>
- Type Parameters:
T- The bean type
- All Superinterfaces:
AnnotationMetadata, AnnotationMetadataDelegate, AnnotationMetadataProvider, AnnotationSource, ArgumentCoercible<T>, BeanContextConditional, BeanDefinition<T>, BeanDefinitionReference<T>, BeanInfo<T>, BeanType<T>, InstantiatableBeanDefinition<T>, Named, Ordered, QualifiedBeanType<T>
- All Known Implementing Classes:
ReflectionBeanDefinition
BeanDefinitionRegistry at runtime.
This differs from BeanDefinitionRegistry.registerSingleton(Object) in that
beans registered this way can be created lazily or not at all and participate
more completely in the life cycle of the BeanContext (for examples event listeners like BeanCreatedEventListener will be fired).
Note that it is generally not recommended to use this approach and build time bean computation is preferred. This type is designed to support a few limited use cases where runtime bean registration is required.
- Since:
- 3.6.0
- Author:
- graemerocher
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceA builder for constructingRuntimeBeanDefinitioninstances.static interfaceThe context of a single creation of a bean built at runtime, passed to the bean factory of a definition built withbuilder(Argument, Function).static interfaceThe context of a single disposal of a bean built at runtime, passed to the disposer of a definition built withRuntimeBeanDefinition.Builder.injectedDisposer(BiConsumer).static interfaceThe lookups a runtime built bean can perform while it is being created or disposed of. -
Field Summary
Fields inherited from interface AnnotationMetadata
CLASS_NAME_SUFFIX, EMPTY_METADATA, VALUE_MEMBERFields inherited from interface AnnotationSource
EMPTYFields inherited from interface Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Method Summary
Modifier and TypeMethodDescriptionstatic <B> RuntimeBeanDefinition.Builder<B> builder(B bean) A new builder for constructing and configuring runtime created beans.static <B> RuntimeBeanDefinition.Builder<B> builder(Argument<B> beanType, Function<RuntimeBeanDefinition.CreationContext, B> beanFactory) A new builder for constructing and configuring runtime created beans where the bean factory receives theRuntimeBeanDefinition.CreationContextof each creation.static <B> RuntimeBeanDefinition.Builder<B> A new builder for constructing and configuring runtime created beans.static <B> RuntimeBeanDefinition.Builder<B> builder(Class<B> beanType, Function<RuntimeBeanDefinition.CreationContext, B> beanFactory) A new builder for constructing and configuring runtime created beans where the bean factory receives theRuntimeBeanDefinition.CreationContextof each creation.static <B> RuntimeBeanDefinition.Builder<B> A new builder for constructing and configuring runtime created beans.default AnnotationMetadataSupplies the metadata.default Stringdefault Collection<String> The types this definition can answerBeanDefinition.getTypeArguments(String)for.getTypeArguments(@Nullable String type) Return the type arguments for the given interface or super type for this bean.getTypeArguments(Class<?> type) Return the type arguments for the given interface or super type for this bean.default booleandefault booleandefault booleanisEnabled(BeanContext context, @Nullable BeanResolutionContext resolutionContext) Return whether this component is enabled for the given context.default booleandefault booleandefault BeanDefinition<T> load()Loads the bean definition.default BeanDefinition<T> load(BeanContext context) Loads the bean definition for the currentBeanContext.static <B> RuntimeBeanDefinition<B> of(B bean) Creates a new effectively singleton bean definition that references the given bean.static <B> RuntimeBeanDefinition<B> Creates a new bean definition that will resolve the bean from the given supplier.Methods inherited from interface AnnotationMetadata
enumValuesSet, enumValuesSet, getValues, hasDeclaredStereotype, hasStereotypeNonRepeating, isAnnotationPresent, isDeclaredAnnotationPresentMethods inherited from interface AnnotationMetadataDelegate
booleanValue, booleanValue, booleanValue, booleanValue, classValue, classValue, classValue, classValue, classValues, classValues, classValues, classValues, copyAnnotationMetadata, doubleValue, doubleValue, doubleValue, enumValue, enumValue, enumValue, enumValue, enumValues, enumValues, enumValues, enumValues, findAnnotation, findAnnotation, findDeclaredAnnotation, findDeclaredAnnotation, findRepeatableAnnotation, findRepeatableAnnotation, getAnnotation, getAnnotation, getAnnotationNameByStereotype, getAnnotationNameByStereotype, getAnnotationNames, getAnnotationNamesByStereotype, getAnnotationNamesByStereotype, getAnnotationType, getAnnotationType, getAnnotationTypeByStereotype, getAnnotationTypeByStereotype, getAnnotationTypesByStereotype, getAnnotationTypesByStereotype, getAnnotationTypesByStereotype, getAnnotationValuesByName, getAnnotationValuesByStereotype, getAnnotationValuesByType, getDeclaredAnnotation, getDeclaredAnnotation, getDeclaredAnnotationNameByStereotype, getDeclaredAnnotationNames, getDeclaredAnnotationNamesByStereotype, getDeclaredAnnotationTypeByStereotype, getDeclaredAnnotationTypeByStereotype, getDeclaredAnnotationValuesByName, getDeclaredAnnotationValuesByType, getDeclaredMetadata, getDeclaredStereotypeAnnotationNames, getDefaultValue, getDefaultValue, getDefaultValue, getDefaultValue, getDefaultValues, getStereotypeAnnotationNames, getTargetAnnotationMetadata, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValues, getValues, hasAnnotation, hasAnnotation, hasDeclaredAnnotation, hasDeclaredAnnotation, hasDeclaredStereotype, hasDeclaredStereotype, hasDeclaredStereotype, hasEvaluatedExpressions, hasPropertyExpressions, hasSimpleAnnotation, hasSimpleDeclaredAnnotation, hasStereotype, hasStereotype, hasStereotype, hasStereotype, intValue, intValue, intValue, isAnnotationPresent, isDeclaredAnnotationPresent, isEmpty, isFalse, isFalse, isPresent, isPresent, isRepeatableAnnotation, isRepeatableAnnotation, isTrue, isTrue, longValue, longValue, stringValue, stringValue, stringValue, stringValue, stringValues, stringValues, stringValues, stringValues, synthesize, synthesize, synthesizeAll, synthesizeAnnotationsByType, synthesizeDeclared, synthesizeDeclared, synthesizeDeclared, synthesizeDeclaredAnnotationsByTypeMethods inherited from interface BeanContextConditional
isEnabledMethods inherited from interface BeanDefinition
asArgument, findMethod, findPossibleMethods, getBeanDescription, getBeanDescription, getBeanType, getConstructor, getContainerElement, getDeclaringType, getDefaultImplementation, getExecutableMethods, getExecutableMethodsForProcessing, getGenericBeanType, getInjectedFields, getInjectedMethods, getName, getPostConstructMethods, getPreDestroyMethods, getReplacesDefinition, getRequiredComponents, getRequiredMethod, getScope, getScopeName, getTypeArguments, getTypeInformation, getTypeParameters, getTypeParameters, hasAnnotatedMethod, isAbstract, isCanBeReplaced, isCandidateBean, isIterable, isProxyMethods inherited from interface BeanDefinitionReference
getIndexes, isParallel, isProxiedBean, isProxyTargetMethods inherited from interface BeanType
getBeanName, getExposedTypes, isContainerType, isPrimary, requiresMethodProcessingMethods inherited from interface InstantiatableBeanDefinition
instantiate, instantiateMethods inherited from interface QualifiedBeanType
getDeclaredQualifier, resolveDynamicQualifier
-
Method Details
-
getAnnotationMetadata
Description copied from interface:AnnotationMetadataProviderSupplies the metadata. Defaults toAnnotationMetadata.EMPTY_METADATA.- Specified by:
getAnnotationMetadatain interfaceAnnotationMetadataProvider- Returns:
- The
AnnotationMetadata
-
isEnabled
Description copied from interface:BeanContextConditionalReturn whether this component is enabled for the given context.- Specified by:
isEnabledin interfaceBeanContextConditional- Parameters:
context- The contextresolutionContext- The bean resolution context- Returns:
- True if it is
-
getTypeArguments
Description copied from interface:BeanDefinitionReturn the type arguments for the given interface or super type for this bean.- Specified by:
getTypeArgumentsin interfaceBeanDefinition<T>- Parameters:
type- The super class or interface type- Returns:
- The type arguments
-
getTypeArguments
Return the type arguments for the given interface or super type for this bean.A runtime definition has no recorded arguments to look the name up in, so it resolves the name against the bean type's own hierarchy and then answers as
getTypeArguments(Class)does, which keeps the two lookups in agreement. A name that is not a super type of the bean answers empty.- Specified by:
getTypeArgumentsin interfaceBeanDefinition<T>- Parameters:
type- The super class or interface type- Returns:
- The type arguments
-
getTypeArgumentKeys
The types this definition can answerBeanDefinition.getTypeArguments(String)for.A definition computed at build time records the type arguments the compiler resolved for the bean type and for every super class and interface above it, keyed by type. This returns those keys, so a consumer that needs every super type the bean supplies arguments to can read what was recorded instead of rediscovering the hierarchy reflectively.
A key is a class name in the form
Class.getName()returns, which is what the definition stores; nothing here loads it. A caller that only needs the arguments passes the key straight back toBeanDefinition.getTypeArguments(String), and one that needs aClassloads the name itself. Every key answers that lookup, though the answer may be an empty list: a super type that carries no arguments of its own is still part of what was recorded.The iteration order is unspecified and is not the order of the hierarchy. A definition that records nothing answers empty - including for its own
BeanDefinition.getBeanType(), whichBeanDefinition.getTypeArguments()then answers empty for as well.A
ProxyBeanDefinitionanswers for the hierarchy of the type it proxies rather than for the generated proxy class, so its keys nameProxyBeanDefinition.getTargetType()and the super types above it.Nothing is recorded for a runtime definition, so this is the bean type and every super class and interface above it, which is the hierarchy a build time definition records for the same classes. It answers empty when none of them declares a type parameter, again as a build time definition does.
The test is what the hierarchy declares rather than what resolves, so that the keys do not depend on whether an argument could be resolved. A bean implementing a raw or unbound super type -
RawRepo implements Repo- namesRepohere exactly as a build time definition does, even thoughgetTypeArguments(Class)answers nothing for it where a build time definition answers the erased variable.- Specified by:
getTypeArgumentKeysin interfaceBeanDefinition<T>- Returns:
- The recorded type keys, never
null
-
isContextScope
default boolean isContextScope()- Specified by:
isContextScopein interfaceBeanDefinitionReference<T>- Returns:
- Is this class context scope
-
isConfigurationProperties
default boolean isConfigurationProperties()- Specified by:
isConfigurationPropertiesin interfaceBeanDefinition<T>- Specified by:
isConfigurationPropertiesin interfaceBeanDefinitionReference<T>- Returns:
- Is this bean a configuration properties.
-
load
Description copied from interface:BeanDefinitionReferenceLoads the bean definition.- Specified by:
loadin interfaceBeanDefinitionReference<T>- Returns:
- The loaded component definition or null if it shouldn't be loaded
-
getBeanDefinitionName
- Specified by:
getBeanDefinitionNamein interfaceBeanDefinitionReference<T>- Returns:
- The class name of the backing
BeanDefinition
-
load
Description copied from interface:BeanDefinitionReferenceLoads the bean definition for the currentBeanContext.- Specified by:
loadin interfaceBeanDefinitionReference<T>- Parameters:
context- The bean context- Returns:
- The loaded bean definition or null if it shouldn't be loaded
-
isPresent
default boolean isPresent()- Specified by:
isPresentin interfaceBeanDefinitionReference<T>- Returns:
- Is the underlying bean type present on the classpath
-
isSingleton
default boolean isSingleton()- Specified by:
isSingletonin interfaceBeanDefinition<T>- Specified by:
isSingletonin interfaceBeanDefinitionReference<T>- Returns:
- Is this bean a singleton.
-
of
Creates a new effectively singleton bean definition that references the given bean.- Type Parameters:
B- The bean type- Parameters:
bean- The bean- Returns:
- The
BeanDefinitionReference - Since:
- 3.6.0
-
of
Creates a new bean definition that will resolve the bean from the given supplier.The bean is by default not singleton and the supplier will be invoked for each injection point.
- Type Parameters:
B- The bean type- Parameters:
beanType- The bean typebeanSupplier- The bean supplier- Returns:
- The
BeanDefinitionReference - Since:
- 3.6.0
-
builder
A new builder for constructing and configuring runtime created beans.- Type Parameters:
B- The bean type- Parameters:
bean- The bean to use- Returns:
- The builder
-
builder
A new builder for constructing and configuring runtime created beans.- Type Parameters:
B- The bean type- Parameters:
beanType- The bean typebeanSupplier- The bean supplier- Returns:
- The builder
-
builder
A new builder for constructing and configuring runtime created beans.- Type Parameters:
B- The bean type- Parameters:
beanType- The bean typebeanSupplier- The bean supplier- Returns:
- The builder
-
builder
static <B> RuntimeBeanDefinition.Builder<B> builder(Class<B> beanType, Function<RuntimeBeanDefinition.CreationContext, B> beanFactory) A new builder for constructing and configuring runtime created beans where the bean factory receives theRuntimeBeanDefinition.CreationContextof each creation.The creation context carries the beans resolved for the injection points declared with
RuntimeBeanDefinition.Builder.injectionPoint(Argument)and the injection point the bean is being created for.- Type Parameters:
B- The bean type- Parameters:
beanType- The bean typebeanFactory- The bean factory that receives theRuntimeBeanDefinition.CreationContext- Returns:
- The builder
- Since:
- 5.2.0
-
builder
static <B> RuntimeBeanDefinition.Builder<B> builder(Argument<B> beanType, Function<RuntimeBeanDefinition.CreationContext, B> beanFactory) A new builder for constructing and configuring runtime created beans where the bean factory receives theRuntimeBeanDefinition.CreationContextof each creation.The creation context carries the beans resolved for the injection points declared with
RuntimeBeanDefinition.Builder.injectionPoint(Argument)and the injection point the bean is being created for.- Type Parameters:
B- The bean type- Parameters:
beanType- The bean typebeanFactory- The bean factory that receives theRuntimeBeanDefinition.CreationContext- Returns:
- The builder
- Since:
- 5.2.0
-