Interface BeanDefinition<T>

Type Parameters:
T - The bean type
All Superinterfaces:
AnnotationMetadata, AnnotationMetadataDelegate, AnnotationMetadataProvider, AnnotationSource, ArgumentCoercible<T>, BeanContextConditional, BeanInfo<T>, BeanType<T>, Named, Ordered, QualifiedBeanType<T>
All Known Subinterfaces:
DelegatingBeanDefinition<T>, DisposableBeanDefinition<T>, DisposableIntercepted<T>, InitializableIntercepted<T>, InitializingBeanDefinition<T>, InjectableBeanDefinition<T>, InstantiatableBeanDefinition<T>, InterceptedBeanDefinition<T>, ParameterizedInterceptedBeanDefinition<T>, ParameterizedProxyBeanDefinition<T>, ParametrizedInstantiatableBeanDefinition<T>, ProxyBeanDefinition<T>, ProxyInterceptedBeanDefinition<T>, RuntimeBeanDefinition<T>, ValidatedBeanDefinition<T>
All Known Implementing Classes:
AbstractInitializableBeanDefinition, AbstractInitializableBeanDefinitionAndReference, AbstractProviderDefinition, ApplicationEventPublisherFactory, BeanProviderDefinition, DisabledBean, InterceptorRegistryBean, JakartaProviderBeanDefinition, JavaxProviderBeanDefinition, ReflectionBeanDefinition

public interface BeanDefinition<T> extends QualifiedBeanType<T>, Named, BeanType<T>, 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
Author:
Graeme Rocher
  • Method Details

    • getTypeInformation

      default TypeInformation<T> getTypeInformation()
      Returns:
      The type information for the bean.
      Since:
      4.8.0
    • 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<Argument<?>> getContainerElement()
      If BeanType.isContainerType() returns true this will return the container element.
      Returns:
      The container element.
    • isCandidateBean

      default boolean isCandidateBean(@Nullable 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 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

      default String getName()
      Specified by:
      getName in interface BeanType<T>
      Specified by:
      getName in interface 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(Class<? extends Annotation> annotationClass, String methodName, 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

      default Argument<T> asArgument()
      Specified by:
      asArgument in interface ArgumentCoercible<T>
      Specified by:
      asArgument in interface BeanInfo<T>
      Returns:
      The argument
    • isProxy

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

      default List<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

      default List<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

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

      default 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

      default List<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
    • getTypeArgumentKeys

      default Collection<String> getTypeArgumentKeys()
      The types this definition can answer 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 to getTypeArguments(String), and one that needs a Class loads 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 getBeanType(), which getTypeArguments() then answers empty for as well.

      A ProxyBeanDefinition answers for the hierarchy of the type it proxies rather than for the generated proxy class, so its keys name ProxyBeanDefinition.getTargetType() and the super types above it.

      Returns:
      The recorded type keys, never null
      Since:
      5.2.0
    • 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 Argument<T> getGenericBeanType()
      Specified by:
      getGenericBeanType in interface BeanInfo<T>
      Returns:
      The generic bean type
    • getBeanDescription

      default String getBeanDescription(TypeInformation.TypeFormat typeFormat, boolean includeArguments)
      Gets a description of the bean as close as possible to source representation.
      Parameters:
      typeFormat - The type format to use.
      includeArguments - Whether to include arguments.
      Returns:
      The bean description.
      Since:
      4.8.0
    • getBeanDescription

      default String getBeanDescription(TypeInformation.TypeFormat typeFormat)
      Gets a description of the bean as close as possible to source representation.
      Parameters:
      typeFormat - The type format to use.
      Returns:
      The bean description.
      Since:
      4.8.0
    • getDefaultImplementation

      default @Nullable Class<?> getDefaultImplementation()
      Get the default implementation defined by DefaultImplementation.
      Returns:
      The default implementation
      Since:
      5.0
    • isCanBeReplaced

      default boolean isCanBeReplaced()
      Determines if another bean definition can replace this bean definition. Some bean definitions are not replaceable. See Infrastructure.
      Returns:
      true if it can be replaced
      Since:
      5.0
    • getReplacesDefinition

      default @Nullable ReplacesDefinition<T> getReplacesDefinition()
      The replacement defined by Replaces.
      Returns:
      The bean replacement definition if present, otherwise null.
      Since:
      5.0
    • getExecutableMethodsForProcessing

      default Iterable<ExecutableMethod<T,?>> getExecutableMethodsForProcessing()
      When BeanType.requiresMethodProcessing() is true, this method returns the methods that require processing. Executable methods with Executable.processOnStartup() set to true.
      Returns:
      The methods that require processing.
      Since:
      5.0
      See Also: