org.springframework.context.annotation

Class ClassPathBeanDefinitionScanner

    • Method Detail

      • getBeanDefinitionDefaults

        public BeanDefinitionDefaults getBeanDefinitionDefaults()
        Return the defaults to use for detected beans (never null).
        Since:
        4.1
      • setAutowireCandidatePatterns

        public void setAutowireCandidatePatterns(@Nullable
                                                 java.lang.String... autowireCandidatePatterns)
        Set the name-matching patterns for determining autowire candidates.
        Parameters:
        autowireCandidatePatterns - the patterns to match against
      • setIncludeAnnotationConfig

        public void setIncludeAnnotationConfig(boolean includeAnnotationConfig)
        Specify whether to register annotation config post-processors.

        The default is to register the post-processors. Turn this off to be able to ignore the annotations or to process them differently.

      • scan

        public int scan(java.lang.String... basePackages)
        Perform a scan within the specified base packages.
        Parameters:
        basePackages - the packages to check for annotated classes
        Returns:
        number of beans registered
      • doScan

        protected java.util.Set<BeanDefinitionHolder> doScan(java.lang.String... basePackages)
        Perform a scan within the specified base packages, returning the registered bean definitions.

        This method does not register an annotation config processor but rather leaves this up to the caller.

        Parameters:
        basePackages - the packages to check for annotated classes
        Returns:
        set of beans registered if any for tooling registration purposes (never null)
      • postProcessBeanDefinition

        protected void postProcessBeanDefinition(AbstractBeanDefinition beanDefinition,
                                                 java.lang.String beanName)
        Apply further settings to the given bean definition, beyond the contents retrieved from scanning the component class.
        Parameters:
        beanDefinition - the scanned bean definition
        beanName - the generated bean name for the given bean
      • registerBeanDefinition

        protected void registerBeanDefinition(BeanDefinitionHolder definitionHolder,
                                              BeanDefinitionRegistry registry)
        Register the specified bean with the given registry.

        Can be overridden in subclasses, e.g. to adapt the registration process or to register further bean definitions for each scanned bean.

        Parameters:
        definitionHolder - the bean definition plus bean name for the bean
        registry - the BeanDefinitionRegistry to register the bean with
      • checkCandidate

        protected boolean checkCandidate(java.lang.String beanName,
                                         BeanDefinition beanDefinition)
                                  throws java.lang.IllegalStateException
        Check the given candidate's bean name, determining whether the corresponding bean definition needs to be registered or conflicts with an existing definition.
        Parameters:
        beanName - the suggested name for the bean
        beanDefinition - the corresponding bean definition
        Returns:
        true if the bean can be registered as-is; false if it should be skipped because there is an existing, compatible bean definition for the specified name
        Throws:
        ConflictingBeanDefinitionException - if an existing, incompatible bean definition has been found for the specified name
        java.lang.IllegalStateException
      • isCompatible

        protected boolean isCompatible(BeanDefinition newDefinition,
                                       BeanDefinition existingDefinition)
        Determine whether the given new bean definition is compatible with the given existing bean definition.

        The default implementation considers them as compatible when the existing bean definition comes from the same source or from a non-scanning source.

        Parameters:
        newDefinition - the new bean definition, originated from scanning
        existingDefinition - the existing bean definition, potentially an explicitly defined one or a previously generated one from scanning
        Returns:
        whether the definitions are considered as compatible, with the new definition to be skipped in favor of the existing definition