Interface BeanDefinition<T>

Type Parameters:
T - The bean type
All Superinterfaces:
io.micronaut.core.annotation.AnnotationMetadata, io.micronaut.core.annotation.AnnotationMetadataDelegate, io.micronaut.core.annotation.AnnotationMetadataProvider, io.micronaut.core.annotation.AnnotationSource, io.micronaut.core.type.ArgumentCoercible<T>, BeanContextConditional, io.micronaut.core.beans.BeanInfo<T>, BeanType<T>, io.micronaut.core.naming.Named, io.micronaut.core.order.Ordered, QualifiedBeanType<T>
All Known Subinterfaces:
DelegatingBeanDefinition<T>, DisposableBeanDefinition<T>, InitializingBeanDefinition<T>, InjectableBeanDefinition<T>, InstantiatableBeanDefinition<T>, ParametrizedInstantiatableBeanDefinition<T>, ProxyBeanDefinition<T>, RuntimeBeanDefinition<T>, ValidatedBeanDefinition<T>
All Known Implementing Classes:
AbstractInitializableBeanDefinition, AbstractInitializableBeanDefinitionAndReference, AbstractProviderDefinition, ApplicationEventPublisherFactory, BeanProviderDefinition, DisabledBean, JakartaProviderBeanDefinition, JavaxProviderBeanDefinition

public interface BeanDefinition<T> extends QualifiedBeanType<T>, io.micronaut.core.naming.Named, BeanType<T>, io.micronaut.core.type.ArgumentCoercible<T>
Defines a bean definition and its requirements. A bean definition must have a singled injectable constructor or a no-args constructor.
Since:
1.0
  • Field Summary

    Fields inherited from interface io.micronaut.core.annotation.AnnotationMetadata

    CLASS_NAME_SUFFIX, EMPTY_METADATA, VALUE_MEMBER

    Fields inherited from interface io.micronaut.core.annotation.AnnotationSource

    EMPTY

    Fields inherited from interface io.micronaut.core.order.Ordered

    HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
  • Method Summary

    Modifier and Type
    Method
    Description
    default @NonNull io.micronaut.core.type.Argument<T>
     
    default <R> Optional<ExecutableMethod<T,R>>
    findMethod(String name, Class<?>... argumentTypes)
    Finds a single ExecutableMethod for the given name and argument types.
    default <R> Stream<ExecutableMethod<T,R>>
    Finds possible methods for the given method name.
    Returns the bean type.
    The single concrete constructor that is an injection point for creating the bean.
    default Optional<io.micronaut.core.type.Argument<?>>
    If BeanType.isContainerType() returns true this will return the container element.
    default @Nullable Qualifier<T>
    Resolve the declared qualifier for this bean.
    default Optional<Class<?>>
     
     
    default io.micronaut.core.type.Argument<T>
     
    All the fields that require injection.
    All methods that require injection.
    default @NonNull String
     
    All the methods that should be called once the bean has been fully initialized and constructed.
    All the methods that should be called when the object is to be destroyed.
    default Collection<Class<?>>
     
    default <R> ExecutableMethod<T,R>
    getRequiredMethod(String name, Class<?>... argumentTypes)
    Finds a single ExecutableMethod for the given name and argument types.
    default Optional<Class<? extends Annotation>>
     
    default Optional<String>
     
    default @NonNull List<io.micronaut.core.type.Argument<?>>
    If the bean itself declares any type arguments this method will return the classes that represent those types.
    default @NonNull List<io.micronaut.core.type.Argument<?>>
    Return the type arguments for the given interface or super type for this bean.
    default @NonNull List<io.micronaut.core.type.Argument<?>>
    Return the type arguments for the given interface or super type for this bean.
    default @NonNull Class<?>[]
    Returns the type parameters as a class array for the bean type.
    default @NonNull Class<?>[]
    getTypeParameters(@Nullable Class<?> type)
    Returns the type parameters as a class array for the given type.
    default boolean
    hasAnnotatedMethod(@NonNull Class<? extends Annotation> annotationClass, @NonNull String methodName, @NonNull Class<?>... argumentTypes)
    Whether an ExecutableMethod exists which is annotated with the supplied annotation
    default boolean
     
    default boolean
    isCandidateBean(@Nullable io.micronaut.core.type.Argument<?> beanType)
    Return whether this bean type is a candidate for dependency injection for the passed type.
    default boolean
     
    default boolean
     
    default boolean
    Whether this bean definition represents a proxy.
    default boolean
     
    default @Nullable Qualifier<T>
     

    Methods inherited from interface io.micronaut.core.annotation.AnnotationMetadata

    enumValuesSet, enumValuesSet, getValues, hasDeclaredStereotype, hasEvaluatedExpressions, hasStereotypeNonRepeating, isAnnotationPresent, isDeclaredAnnotationPresent

    Methods inherited from interface io.micronaut.core.annotation.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, 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, synthesizeDeclaredAnnotationsByType

    Methods inherited from interface io.micronaut.core.annotation.AnnotationMetadataProvider

    getAnnotationMetadata

    Methods inherited from interface io.micronaut.inject.BeanContextConditional

    isEnabled, isEnabled

    Methods inherited from interface io.micronaut.core.beans.BeanInfo

    getOrder

    Methods inherited from interface io.micronaut.inject.BeanType

    getBeanName, getExposedTypes, isContainerType, isPrimary, requiresMethodProcessing
  • Method Details

    • getScope

      default Optional<Class<? extends Annotation>> getScope()
      Returns:
      The scope of the bean
    • getScopeName

      default Optional<String> getScopeName()
      Returns:
      The name of the scope
    • isSingleton

      default boolean isSingleton()
      Returns:
      Whether the scope is singleton
    • getContainerElement

      default Optional<io.micronaut.core.type.Argument<?>> getContainerElement()
      If BeanType.isContainerType() returns true this will return the container element.
      Returns:
      The container element.
    • isCandidateBean

      default boolean isCandidateBean(@Nullable @Nullable io.micronaut.core.type.Argument<?> beanType)
      Description copied from interface: BeanType
      Return whether this bean type is a candidate for dependency injection for the passed type.
      Specified by:
      isCandidateBean in interface BeanType<T>
      Parameters:
      beanType - The bean type
      Returns:
      True if it is
    • isIterable

      default boolean isIterable()
      Returns:
      Whether the bean declared with EachProperty or EachBean
    • isConfigurationProperties

      default boolean isConfigurationProperties()
      Returns:
      Is the type configuration properties.
    • getBeanType

      Class<T> getBeanType()
      Description copied from interface: BeanType
      Returns the bean type.
      Specified by:
      getBeanType in interface io.micronaut.core.beans.BeanInfo<T>
      Specified by:
      getBeanType in interface BeanType<T>
      Returns:
      The produced bean type
    • getDeclaringType

      default Optional<Class<?>> getDeclaringType()
      Returns:
      The type that declares this definition, null if not applicable.
    • getConstructor

      default ConstructorInjectionPoint<T> getConstructor()
      The single concrete constructor that is an injection point for creating the bean.
      Returns:
      The constructor injection point
    • getRequiredComponents

      default Collection<Class<?>> getRequiredComponents()
      Returns:
      All required components for this entity definition
    • getInjectedMethods

      default Collection<MethodInjectionPoint<T,?>> getInjectedMethods()
      All methods that require injection. This is a subset of all the methods in the class.
      Returns:
      The required properties
    • getInjectedFields

      default Collection<FieldInjectionPoint<T,?>> getInjectedFields()
      All the fields that require injection.
      Returns:
      The required fields
    • getPostConstructMethods

      default Collection<MethodInjectionPoint<T,?>> getPostConstructMethods()
      All the methods that should be called once the bean has been fully initialized and constructed.
      Returns:
      Methods to call post construct
    • getPreDestroyMethods

      default Collection<MethodInjectionPoint<T,?>> getPreDestroyMethods()
      All the methods that should be called when the object is to be destroyed.
      Returns:
      Methods to call pre-destroy
    • getName

      @NonNull default @NonNull String getName()
      Specified by:
      getName in interface BeanType<T>
      Specified by:
      getName in interface io.micronaut.core.naming.Named
      Returns:
      The class name
    • findMethod

      default <R> Optional<ExecutableMethod<T,R>> findMethod(String name, Class<?>... argumentTypes)
      Finds a single ExecutableMethod for the given name and argument types.
      Type Parameters:
      R - The return type
      Parameters:
      name - The method name
      argumentTypes - The argument types
      Returns:
      An optional ExecutableMethod
    • hasAnnotatedMethod

      default boolean hasAnnotatedMethod(@NonNull @NonNull Class<? extends Annotation> annotationClass, @NonNull @NonNull String methodName, @NonNull @NonNull Class<?>... argumentTypes)
      Whether an ExecutableMethod exists which is annotated with the supplied annotation
      Parameters:
      methodName - The method name
      argumentTypes - The argument types
      Returns:
      Whether an ExecutableMethod exists which is annotated with the supplied annotation
      Since:
      4.3.0
    • findPossibleMethods

      default <R> Stream<ExecutableMethod<T,R>> findPossibleMethods(String name)
      Finds possible methods for the given method name.
      Type Parameters:
      R - The return type
      Parameters:
      name - The method name
      Returns:
      The possible methods
    • getExecutableMethods

      default Collection<ExecutableMethod<T,?>> getExecutableMethods()
      Returns:
      The ExecutableMethod instances for this definition
    • asArgument

      @NonNull default @NonNull io.micronaut.core.type.Argument<T> asArgument()
      Specified by:
      asArgument in interface io.micronaut.core.type.ArgumentCoercible<T>
      Specified by:
      asArgument in interface io.micronaut.core.beans.BeanInfo<T>
    • isProxy

      default boolean isProxy()
      Whether this bean definition represents a proxy.
      Returns:
      True if it represents a proxy
    • getTypeArguments

      @NonNull default @NonNull List<io.micronaut.core.type.Argument<?>> getTypeArguments()
      If the bean itself declares any type arguments this method will return the classes that represent those types.
      Returns:
      The type arguments
    • getTypeArguments

      @NonNull default @NonNull List<io.micronaut.core.type.Argument<?>> getTypeArguments(Class<?> type)
      Return the type arguments for the given interface or super type for this bean.
      Parameters:
      type - The super class or interface type
      Returns:
      The type arguments
    • getTypeParameters

      @NonNull default @NonNull Class<?>[] getTypeParameters(@Nullable @Nullable Class<?> type)
      Returns the type parameters as a class array for the given type.
      Parameters:
      type - The type
      Returns:
      The type parameters
    • getTypeParameters

      @NonNull default @NonNull Class<?>[] getTypeParameters()
      Returns the type parameters as a class array for the bean type.
      Returns:
      The type parameters for the bean type as a class array.
    • getTypeArguments

      @NonNull default @NonNull List<io.micronaut.core.type.Argument<?>> getTypeArguments(String type)
      Return the type arguments for the given interface or super type for this bean.
      Parameters:
      type - The super class or interface type
      Returns:
      The type arguments
    • getRequiredMethod

      default <R> ExecutableMethod<T,R> getRequiredMethod(String name, Class<?>... argumentTypes)
      Finds a single ExecutableMethod for the given name and argument types.
      Type Parameters:
      R - The return type
      Parameters:
      name - The method name
      argumentTypes - The argument types
      Returns:
      An optional ExecutableMethod
      Throws:
      IllegalStateException - If the method cannot be found
    • isAbstract

      default boolean isAbstract()
      Returns:
      Whether the bean definition is abstract
    • getGenericBeanType

      default io.micronaut.core.type.Argument<T> getGenericBeanType()
      Specified by:
      getGenericBeanType in interface io.micronaut.core.beans.BeanInfo<T>
    • getDeclaredQualifier

      @Nullable default @Nullable Qualifier<T> getDeclaredQualifier()
      Resolve the declared qualifier for this bean.
      Specified by:
      getDeclaredQualifier in interface QualifiedBeanType<T>
      Returns:
      The qualifier or null if this isn't one
    • resolveDynamicQualifier

      @Nullable default @Nullable Qualifier<T> resolveDynamicQualifier()
      Specified by:
      resolveDynamicQualifier in interface QualifiedBeanType<T>
      Returns:
      Method that can be overridden to resolve a dynamic qualifier