Example usage for org.springframework.beans.factory.config ConfigurableListableBeanFactory getBeanNamesForType

List of usage examples for org.springframework.beans.factory.config ConfigurableListableBeanFactory getBeanNamesForType

Introduction

In this page you can find the example usage for org.springframework.beans.factory.config ConfigurableListableBeanFactory getBeanNamesForType.

Prototype

String[] getBeanNamesForType(ResolvableType type, boolean includeNonSingletons, boolean allowEagerInit);

Source Link

Document

Return the names of beans matching the given type (including subclasses), judging from either bean definitions or the value of getObjectType in the case of FactoryBeans.

Usage

From source file:org.bigtester.ate.model.data.CaseDataProcessor.java

/**
 * {@inheritDoc}/* w  w w  .  java 2 s .co m*/
 */
@Override
public void postProcessBeanFactory(@Nullable ConfigurableListableBeanFactory beanFactory)
        throws BeansException {
    if (beanFactory == null)
        throw new IllegalStateException("Spring Container initialization error");
    String[] homePageNames = beanFactory.getBeanNamesForType(Homepage.class, true, false);
    String[] lastPageNames = beanFactory.getBeanNamesForType(Lastpage.class, true, false);
    String[] regularPageNames = beanFactory.getBeanNamesForType(RegularPage.class, true, false);

    allPageNames = ArrayUtils.addAll(homePageNames, lastPageNames);
    allPageNames = ArrayUtils.addAll(allPageNames, regularPageNames);

    for (int i = 0; i < getAllPageNames().length; i++) {
        pageBeanDefs.add(beanFactory.getBeanDefinition(getAllPageNames()[i]));
    }

    for (int j = 0; j < pageBeanDefs.size(); j++) {
        if (null != pageBeanDefs.get(j).getPropertyValues()
                .getPropertyValue(XsdElementConstants.ATTR_BASEPAGEOBJECT_DATAFILE)) {
            caseDataFiles.add(new FileSystemResource((String) pageBeanDefs.get(j).getPropertyValues()
                    .getPropertyValue(XsdElementConstants.ATTR_BASEPAGEOBJECT_DATAFILE).getValue()));
        }
    }

    if (!caseDataFiles.isEmpty()) {
        dbInit = GlobalUtils.findDBInitializer(beanFactory);
        try {
            getDbInit().setInitXmlFiles(caseDataFiles);
        } catch (IOException e) {
            throw new BeanDefinitionValidationException("Page data file in page attribute can't be read!", e);
        }
        try {
            getDbInit().initialize(beanFactory);
        } catch (MalformedURLException | DatabaseUnitException | SQLException e) {
            throw new FatalBeanException("Case database creation error!", e);
        }
    }
}

From source file:org.bigtester.ate.model.page.elementaction.SendKeysActionPostBeanProcessor.java

/**
 * {@inheritDoc}//from   w w  w  .j  ava 2 s  . c o m
 */
@Override
public void postProcessBeanFactory(@Nullable ConfigurableListableBeanFactory beanFactory)
        throws BeansException {
    if (beanFactory == null)
        throw new IllegalStateException("Spring Container initialization error");
    // String[] homePageNames =
    // beanFactory.getBeanNamesForType(IStepInputData.class, true, false);
    String[] allSendKeysActions = beanFactory.getBeanNamesForType(SendKeysAction.class, true, false);
    for (int index = 0; index < allSendKeysActions.length; index++) {
        BeanDefinition sendKeyActDef = beanFactory.getBeanDefinition(allSendKeysActions[index]);
        String dataValue = ((RuntimeBeanReference) sendKeyActDef.getConstructorArgumentValues()
                .getGenericArgumentValue(RuntimeBeanReference.class).getValue()).getBeanName();
        //.getAttribute(XsdElementConstants.ATTR_SENDKEYSACTION_DATAVALUE);
        if (null == dataValue) {
            throw new IllegalStateException("Spring Container sendKeyActionValue initialization error");
        } else {
            try {
                beanFactory.getBeanDefinition(dataValue);
            } catch (NoSuchBeanDefinitionException NoBeanDef) {

                String idstr;
                BeanDefinitionBuilder definitionBuilder;

                if (StringUtils.isEmpty(dataValue)) {
                    definitionBuilder = BeanDefinitionBuilder
                            .genericBeanDefinition(RandomAlphaTextValueDataHolder.class);
                    idstr = (String) sendKeyActDef.getAttribute("id")
                            + "_SendKeysRandomAlphaTextDataValueBean_ID";
                    definitionBuilder.addConstructorArgValue(idstr);
                    definitionBuilder.addConstructorArgValue(10);

                } else {
                    definitionBuilder = BeanDefinitionBuilder
                            .genericBeanDefinition(ManualAssignedValueDataHolder.class);

                    definitionBuilder.addConstructorArgValue(EnumRunTimeDataType.TEXT);
                    definitionBuilder.addConstructorArgValue(dataValue);

                    idstr = (String) sendKeyActDef.getAttribute("id") + "_SendKeysDataValueBean_ID";
                    definitionBuilder.addConstructorArgValue(idstr);

                }

                getBdReg().registerBeanDefinition(idstr, definitionBuilder.getBeanDefinition());
                sendKeyActDef.setAttribute(XsdElementConstants.ATTR_SENDKEYSACTION_DATAVALUE, idstr);
                sendKeyActDef.getConstructorArgumentValues().getGenericArgumentValue(RuntimeBeanReference.class)
                        .setValue(new RuntimeBeanReference(idstr));
            }
        }
    }

}

From source file:org.bigtester.ate.model.page.elementfind.ElementFinderIndexOfSameProcessor.java

/**
 * {@inheritDoc}/*from w w w  .j a v  a  2s .  c  om*/
 */
@Override
public void postProcessBeanFactory(@Nullable ConfigurableListableBeanFactory beanFactory)
        throws BeansException {
    if (beanFactory == null)
        throw new IllegalStateException("Spring Container initialization error");
    // String[] homePageNames =
    // beanFactory.getBeanNamesForType(IStepInputData.class, true, false);
    String[] elementFinders = beanFactory.getBeanNamesForType(AbstractElementFind.class, true, false);
    for (int index = 0; index < elementFinders.length; index++) {
        BeanDefinition elementFinderDef = beanFactory.getBeanDefinition(elementFinders[index]);

        Object indexOfSameElementsRef = null; // NOPMD
        if (elementFinderDef.getPropertyValues()
                .getPropertyValue(XsdElementConstants.ATTR_GENERICELEMENTFIND_INDEXOFSAMEELEMENTS) != null) {
            indexOfSameElementsRef = elementFinderDef.getPropertyValues()
                    .getPropertyValue(XsdElementConstants.ATTR_GENERICELEMENTFIND_INDEXOFSAMEELEMENTS)
                    .getValue();
        }
        if (indexOfSameElementsRef == null)
            continue;
        String dataValue = ((RuntimeBeanReference) indexOfSameElementsRef).getBeanName();

        if (null == dataValue) {
            throw new IllegalStateException("Spring Container sendKeyActionValue initialization error");
        } else {
            try {
                beanFactory.getBeanDefinition(dataValue);
            } catch (NoSuchBeanDefinitionException NoBeanDef) {

                String idstr;
                int intDataValue;
                BeanDefinitionBuilder definitionBuilder;

                if (StringUtils.isEmpty(dataValue)) {// assign 0
                    intDataValue = 0;
                } else {
                    try {
                        intDataValue = Integer.parseInt(dataValue);//NOPMD
                    } catch (NumberFormatException nonNumeric) {
                        intDataValue = 0;
                    }
                }
                definitionBuilder = BeanDefinitionBuilder
                        .genericBeanDefinition(AutoIncrementalDataHolder.class);

                definitionBuilder.addConstructorArgValue(intDataValue);
                definitionBuilder.addConstructorArgValue(1);

                idstr = (String) elementFinderDef.getAttribute("id") + "_elementfinderIndexOfSameElements_ID";

                getBdReg().registerBeanDefinition(idstr, definitionBuilder.getBeanDefinition());

                elementFinderDef.getPropertyValues()
                        .removePropertyValue(XsdElementConstants.ATTR_GENERICELEMENTFIND_INDEXOFSAMEELEMENTS);
                elementFinderDef.getPropertyValues().addPropertyValue(
                        XsdElementConstants.ATTR_GENERICELEMENTFIND_INDEXOFSAMEELEMENTS,
                        new RuntimeBeanReference(idstr));

            }
        }
    }

}

From source file:com.brienwheeler.lib.spring.beans.PropertyPlaceholderConfigurer.java

@Override
protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess, Properties properties)
        throws BeansException {
    ContextData contextData;/*w w  w  .j  a v a2 s.co  m*/
    synchronized (contextDataMap) {
        contextData = contextDataMap.get(beanFactoryToProcess);
        if (contextData == null) {
            contextData = new ContextData();
            contextDataMap.put(beanFactoryToProcess, contextData);
        }
    }

    int ppcCount = beanFactoryToProcess.getBeanNamesForType(PropertyPlaceholderConfigurer.class, true,
            false).length;
    synchronized (contextData) {
        /*
         * Spring calls all placeholder configurers according to their Order value.
         * We want to aggregate all placeholder definitions at the same Order value and
         * resolve them at the sane time, to ease inter-file dependency management.
         */

        /*
         * First we check to see if we have previously aggregated properties for a
         * different order value.  If so, resolve the previously aggregated properties
         * and clear out the aggregation before proceeding. 
         */
        Integer previousOrder = contextData.isOrderChanging(getOrder());
        if (previousOrder != null) {
            if (!quiet)
                log.info("Processing merged context properties of order " + previousOrder);
            processProperties(contextData.getProperties(), placeholderPrefix, placeholderSuffix);
            contextData.clearProperties();
        }

        /*
         * Now we just merge these definitions into the current Order level aggregation.
         * We'll process them when we hit another placeholder configurer with a different
         * Order value, or when we hit the last placeholder configurer in the context.
         */
        CollectionUtils.mergePropertiesIntoMap(properties, contextData.getProperties());

        /*
         * Finally, if this is the last placeholder configurer in the context we need
         * to resolve the aggregated properties and call Spring to process these into
         * bean defintions, et al.
         */
        if (contextData.incrementPpcCount() == ppcCount) {
            if (!quiet)
                log.info("Processing merged context properties of order " + getOrder());
            processProperties(contextData.getProperties(), placeholderPrefix, placeholderSuffix);
            contextData.clearProperties();
            log.info("Resolving context placeholders");
            super.processProperties(beanFactoryToProcess, contextData.getProperties());
        }
    }
}

From source file:org.sipfoundry.sipxconfig.rest.SipxSpringBeanRouter.java

@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory factory) {
    String[] names = isFindInAncestors()
            ? beanNamesForTypeIncludingAncestors(factory, Resource.class, true, true)
            : factory.getBeanNamesForType(Resource.class, true, true);

    for (String name : names) {
        final String uri = resolveUri(name, factory);
        if (uri != null) {
            attachFinder(uri, createFinder(factory, name));
        }/*from   ww  w  . jav a 2 s. c  o  m*/
    }
}

From source file:org.springframework.boot.autoconfigure.condition.AbstractOnBeanCondition.java

protected boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata, List<String> beanClasses,
        List<String> beanNames) throws LinkageError {

    String checking = ConditionLogUtils.getPrefix(this.logger, metadata);

    SearchStrategy search = (SearchStrategy) metadata.getAnnotationAttributes(annotationClass().getName())
            .get("search");
    search = search == null ? SearchStrategy.ALL : search;

    boolean considerHierarchy = search == SearchStrategy.ALL;
    boolean parentOnly = search == SearchStrategy.PARENTS;

    List<String> beanClassesFound = new ArrayList<String>();
    List<String> beanNamesFound = new ArrayList<String>();

    // eagerInit set to false to prevent early instantiation (some
    // factory beans will not be able to determine their object type at this
    // stage, so those are not eligible for matching this condition)
    ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
    if (parentOnly) {
        BeanFactory parent = beanFactory.getParentBeanFactory();
        if (!(parent instanceof ConfigurableListableBeanFactory)) {
            throw new IllegalStateException(
                    "Cannot use parentOnly if parent is not ConfigurableListableBeanFactory");
        }//from  ww  w .j  a  va  2 s .  c  o m
        beanFactory = (ConfigurableListableBeanFactory) parent;
    }
    for (String beanClass : beanClasses) {
        try {
            Class<?> type = ClassUtils.forName(beanClass, context.getClassLoader());
            String[] beans = (considerHierarchy
                    ? BeanFactoryUtils.beanNamesForTypeIncludingAncestors(beanFactory, type, false, false)
                    : beanFactory.getBeanNamesForType(type, false, false));
            if (beans.length != 0) {
                beanClassesFound.add(beanClass);
            }
        } catch (ClassNotFoundException ex) {
            // swallow exception and continue
        }
    }
    for (String beanName : beanNames) {
        if (considerHierarchy ? beanFactory.containsBean(beanName) : beanFactory.containsLocalBean(beanName)) {
            beanNamesFound.add(beanName);
        }
    }

    boolean result = evaluate(beanClassesFound, beanNamesFound);
    if (this.logger.isDebugEnabled()) {
        logFoundResults(checking, "class", beanClasses, beanClassesFound);
        logFoundResults(checking, "name", beanNames, beanClassesFound);
        this.logger.debug(checking + "Match result is: " + result);
    }
    return result;
}

From source file:org.springframework.context.support.AbstractApplicationContext.java

/**
 * Finish the initialization of this context's bean factory,
 * initializing all remaining singleton beans.
 *//* w  ww .  j a  v  a 2 s  .  c  o  m*/
protected void finishBeanFactoryInitialization(ConfigurableListableBeanFactory beanFactory) {
    // Initialize conversion service for this context.
    if (beanFactory.containsBean(CONVERSION_SERVICE_BEAN_NAME)
            && beanFactory.isTypeMatch(CONVERSION_SERVICE_BEAN_NAME, ConversionService.class)) {
        beanFactory.setConversionService(
                beanFactory.getBean(CONVERSION_SERVICE_BEAN_NAME, ConversionService.class));
    }

    // Register a default embedded value resolver if no bean post-processor
    // (such as a PropertyPlaceholderConfigurer bean) registered any before:
    // at this point, primarily for resolution in annotation attribute values.
    if (!beanFactory.hasEmbeddedValueResolver()) {
        beanFactory.addEmbeddedValueResolver(strVal -> getEnvironment().resolvePlaceholders(strVal));
    }

    // Initialize LoadTimeWeaverAware beans early to allow for registering their transformers early.
    String[] weaverAwareNames = beanFactory.getBeanNamesForType(LoadTimeWeaverAware.class, false, false);
    for (String weaverAwareName : weaverAwareNames) {
        getBean(weaverAwareName);
    }

    // Stop using the temporary ClassLoader for type matching.
    beanFactory.setTempClassLoader(null);

    // Allow for caching all bean definition metadata, not expecting further changes.
    beanFactory.freezeConfiguration();

    // Instantiate all remaining (non-lazy-init) singletons.
    beanFactory.preInstantiateSingletons();
}

From source file:org.springframework.context.support.DefaultLifecycleProcessor.java

/**
 * Retrieve all applicable Lifecycle beans: all singletons that have already been created,
 * as well as all SmartLifecycle beans (even if they are marked as lazy-init).
 * @return the Map of applicable beans, with bean names as keys and bean instances as values
 *///from  www . ja  v a 2s . co  m
protected Map<String, Lifecycle> getLifecycleBeans() {
    ConfigurableListableBeanFactory beanFactory = getBeanFactory();
    Map<String, Lifecycle> beans = new LinkedHashMap<>();
    String[] beanNames = beanFactory.getBeanNamesForType(Lifecycle.class, false, false);
    for (String beanName : beanNames) {
        String beanNameToRegister = BeanFactoryUtils.transformedBeanName(beanName);
        boolean isFactoryBean = beanFactory.isFactoryBean(beanNameToRegister);
        String beanNameToCheck = (isFactoryBean ? BeanFactory.FACTORY_BEAN_PREFIX + beanName : beanName);
        if ((beanFactory.containsSingleton(beanNameToRegister)
                && (!isFactoryBean || matchesBeanType(Lifecycle.class, beanNameToCheck, beanFactory)))
                || matchesBeanType(SmartLifecycle.class, beanNameToCheck, beanFactory)) {
            Object bean = beanFactory.getBean(beanNameToCheck);
            if (bean != this && bean instanceof Lifecycle) {
                beans.put(beanNameToRegister, (Lifecycle) bean);
            }
        }
    }
    return beans;
}

From source file:org.springframework.context.support.PostProcessorRegistrationDelegate.java

public static void invokeBeanFactoryPostProcessors(ConfigurableListableBeanFactory beanFactory,
        List<BeanFactoryPostProcessor> beanFactoryPostProcessors) {

    // Invoke BeanDefinitionRegistryPostProcessors first, if any.
    Set<String> processedBeans = new HashSet<>();

    if (beanFactory instanceof BeanDefinitionRegistry) {
        BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;
        List<BeanFactoryPostProcessor> regularPostProcessors = new LinkedList<>();
        List<BeanDefinitionRegistryPostProcessor> registryProcessors = new LinkedList<>();

        for (BeanFactoryPostProcessor postProcessor : beanFactoryPostProcessors) {
            if (postProcessor instanceof BeanDefinitionRegistryPostProcessor) {
                BeanDefinitionRegistryPostProcessor registryProcessor = (BeanDefinitionRegistryPostProcessor) postProcessor;
                registryProcessor.postProcessBeanDefinitionRegistry(registry);
                registryProcessors.add(registryProcessor);
            } else {
                regularPostProcessors.add(postProcessor);
            }// w  w  w  .ja  va2  s  .  c  o m
        }

        // Do not initialize FactoryBeans here: We need to leave all regular beans
        // uninitialized to let the bean factory post-processors apply to them!
        // Separate between BeanDefinitionRegistryPostProcessors that implement
        // PriorityOrdered, Ordered, and the rest.
        List<BeanDefinitionRegistryPostProcessor> currentRegistryProcessors = new ArrayList<>();

        // First, invoke the BeanDefinitionRegistryPostProcessors that implement PriorityOrdered.
        String[] postProcessorNames = beanFactory.getBeanNamesForType(BeanDefinitionRegistryPostProcessor.class,
                true, false);
        for (String ppName : postProcessorNames) {
            if (beanFactory.isTypeMatch(ppName, PriorityOrdered.class)) {
                currentRegistryProcessors
                        .add(beanFactory.getBean(ppName, BeanDefinitionRegistryPostProcessor.class));
                processedBeans.add(ppName);
            }
        }
        sortPostProcessors(currentRegistryProcessors, beanFactory);
        registryProcessors.addAll(currentRegistryProcessors);
        invokeBeanDefinitionRegistryPostProcessors(currentRegistryProcessors, registry);
        currentRegistryProcessors.clear();

        // Next, invoke the BeanDefinitionRegistryPostProcessors that implement Ordered.
        postProcessorNames = beanFactory.getBeanNamesForType(BeanDefinitionRegistryPostProcessor.class, true,
                false);
        for (String ppName : postProcessorNames) {
            if (!processedBeans.contains(ppName) && beanFactory.isTypeMatch(ppName, Ordered.class)) {
                currentRegistryProcessors
                        .add(beanFactory.getBean(ppName, BeanDefinitionRegistryPostProcessor.class));
                processedBeans.add(ppName);
            }
        }
        sortPostProcessors(currentRegistryProcessors, beanFactory);
        registryProcessors.addAll(currentRegistryProcessors);
        invokeBeanDefinitionRegistryPostProcessors(currentRegistryProcessors, registry);
        currentRegistryProcessors.clear();

        // Finally, invoke all other BeanDefinitionRegistryPostProcessors until no further ones appear.
        boolean reiterate = true;
        while (reiterate) {
            reiterate = false;
            postProcessorNames = beanFactory.getBeanNamesForType(BeanDefinitionRegistryPostProcessor.class,
                    true, false);
            for (String ppName : postProcessorNames) {
                if (!processedBeans.contains(ppName)) {
                    currentRegistryProcessors
                            .add(beanFactory.getBean(ppName, BeanDefinitionRegistryPostProcessor.class));
                    processedBeans.add(ppName);
                    reiterate = true;
                }
            }
            sortPostProcessors(currentRegistryProcessors, beanFactory);
            registryProcessors.addAll(currentRegistryProcessors);
            invokeBeanDefinitionRegistryPostProcessors(currentRegistryProcessors, registry);
            currentRegistryProcessors.clear();
        }

        // Now, invoke the postProcessBeanFactory callback of all processors handled so far.
        invokeBeanFactoryPostProcessors(registryProcessors, beanFactory);
        invokeBeanFactoryPostProcessors(regularPostProcessors, beanFactory);
    }

    else {
        // Invoke factory processors registered with the context instance.
        invokeBeanFactoryPostProcessors(beanFactoryPostProcessors, beanFactory);
    }

    // Do not initialize FactoryBeans here: We need to leave all regular beans
    // uninitialized to let the bean factory post-processors apply to them!
    String[] postProcessorNames = beanFactory.getBeanNamesForType(BeanFactoryPostProcessor.class, true, false);

    // Separate between BeanFactoryPostProcessors that implement PriorityOrdered,
    // Ordered, and the rest.
    List<BeanFactoryPostProcessor> priorityOrderedPostProcessors = new ArrayList<>();
    List<String> orderedPostProcessorNames = new ArrayList<>();
    List<String> nonOrderedPostProcessorNames = new ArrayList<>();
    for (String ppName : postProcessorNames) {
        if (processedBeans.contains(ppName)) {
            // skip - already processed in first phase above
        } else if (beanFactory.isTypeMatch(ppName, PriorityOrdered.class)) {
            priorityOrderedPostProcessors.add(beanFactory.getBean(ppName, BeanFactoryPostProcessor.class));
        } else if (beanFactory.isTypeMatch(ppName, Ordered.class)) {
            orderedPostProcessorNames.add(ppName);
        } else {
            nonOrderedPostProcessorNames.add(ppName);
        }
    }

    // First, invoke the BeanFactoryPostProcessors that implement PriorityOrdered.
    sortPostProcessors(priorityOrderedPostProcessors, beanFactory);
    invokeBeanFactoryPostProcessors(priorityOrderedPostProcessors, beanFactory);

    // Next, invoke the BeanFactoryPostProcessors that implement Ordered.
    List<BeanFactoryPostProcessor> orderedPostProcessors = new ArrayList<>();
    for (String postProcessorName : orderedPostProcessorNames) {
        orderedPostProcessors.add(beanFactory.getBean(postProcessorName, BeanFactoryPostProcessor.class));
    }
    sortPostProcessors(orderedPostProcessors, beanFactory);
    invokeBeanFactoryPostProcessors(orderedPostProcessors, beanFactory);

    // Finally, invoke all other BeanFactoryPostProcessors.
    List<BeanFactoryPostProcessor> nonOrderedPostProcessors = new ArrayList<>();
    for (String postProcessorName : nonOrderedPostProcessorNames) {
        nonOrderedPostProcessors.add(beanFactory.getBean(postProcessorName, BeanFactoryPostProcessor.class));
    }
    invokeBeanFactoryPostProcessors(nonOrderedPostProcessors, beanFactory);

    // Clear cached merged bean definitions since the post-processors might have
    // modified the original metadata, e.g. replacing placeholders in values...
    beanFactory.clearMetadataCache();
}

From source file:org.springframework.context.support.PostProcessorRegistrationDelegate.java

public static void registerBeanPostProcessors(ConfigurableListableBeanFactory beanFactory,
        AbstractApplicationContext applicationContext) {

    String[] postProcessorNames = beanFactory.getBeanNamesForType(BeanPostProcessor.class, true, false);

    // Register BeanPostProcessorChecker that logs an info message when
    // a bean is created during BeanPostProcessor instantiation, i.e. when
    // a bean is not eligible for getting processed by all BeanPostProcessors.
    int beanProcessorTargetCount = beanFactory.getBeanPostProcessorCount() + 1 + postProcessorNames.length;
    beanFactory.addBeanPostProcessor(new BeanPostProcessorChecker(beanFactory, beanProcessorTargetCount));

    // Separate between BeanPostProcessors that implement PriorityOrdered,
    // Ordered, and the rest.
    List<BeanPostProcessor> priorityOrderedPostProcessors = new ArrayList<>();
    List<BeanPostProcessor> internalPostProcessors = new ArrayList<>();
    List<String> orderedPostProcessorNames = new ArrayList<>();
    List<String> nonOrderedPostProcessorNames = new ArrayList<>();
    for (String ppName : postProcessorNames) {
        if (beanFactory.isTypeMatch(ppName, PriorityOrdered.class)) {
            BeanPostProcessor pp = beanFactory.getBean(ppName, BeanPostProcessor.class);
            priorityOrderedPostProcessors.add(pp);
            if (pp instanceof MergedBeanDefinitionPostProcessor) {
                internalPostProcessors.add(pp);
            }//from   w  w w . ja  v a 2  s.  co m
        } else if (beanFactory.isTypeMatch(ppName, Ordered.class)) {
            orderedPostProcessorNames.add(ppName);
        } else {
            nonOrderedPostProcessorNames.add(ppName);
        }
    }

    // First, register the BeanPostProcessors that implement PriorityOrdered.
    sortPostProcessors(priorityOrderedPostProcessors, beanFactory);
    registerBeanPostProcessors(beanFactory, priorityOrderedPostProcessors);

    // Next, register the BeanPostProcessors that implement Ordered.
    List<BeanPostProcessor> orderedPostProcessors = new ArrayList<>();
    for (String ppName : orderedPostProcessorNames) {
        BeanPostProcessor pp = beanFactory.getBean(ppName, BeanPostProcessor.class);
        orderedPostProcessors.add(pp);
        if (pp instanceof MergedBeanDefinitionPostProcessor) {
            internalPostProcessors.add(pp);
        }
    }
    sortPostProcessors(orderedPostProcessors, beanFactory);
    registerBeanPostProcessors(beanFactory, orderedPostProcessors);

    // Now, register all regular BeanPostProcessors.
    List<BeanPostProcessor> nonOrderedPostProcessors = new ArrayList<>();
    for (String ppName : nonOrderedPostProcessorNames) {
        BeanPostProcessor pp = beanFactory.getBean(ppName, BeanPostProcessor.class);
        nonOrderedPostProcessors.add(pp);
        if (pp instanceof MergedBeanDefinitionPostProcessor) {
            internalPostProcessors.add(pp);
        }
    }
    registerBeanPostProcessors(beanFactory, nonOrderedPostProcessors);

    // Finally, re-register all internal BeanPostProcessors.
    sortPostProcessors(internalPostProcessors, beanFactory);
    registerBeanPostProcessors(beanFactory, internalPostProcessors);

    // Re-register post-processor for detecting inner beans as ApplicationListeners,
    // moving it to the end of the processor chain (for picking up proxies etc).
    beanFactory.addBeanPostProcessor(new ApplicationListenerDetector(applicationContext));
}