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

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

Introduction

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

Prototype

<T> Map<String, T> getBeansOfType(@Nullable Class<T> type, boolean includeNonSingletons, boolean allowEagerInit)
        throws BeansException;

Source Link

Document

Return the bean instances that match the given object type (including subclasses), judging from either bean definitions or the value of getObjectType in the case of FactoryBeans.

Usage

From source file:com.mmnaseri.dragonfly.runtime.session.impl.SessionPostProcessorHandler.java

@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    final ArrayList<SessionPostProcessor> postProcessors = new ArrayList<SessionPostProcessor>(
            beanFactory.getBeansOfType(SessionPostProcessor.class, false, true).values());
    Collections.sort(postProcessors, new Comparator<SessionPostProcessor>() {
        @Override//from w  w  w  .  j  ava  2 s.  c  o  m
        public int compare(SessionPostProcessor first, SessionPostProcessor second) {
            Integer firstOrder = first instanceof Ordered ? ((Ordered) first).getOrder() : 0;
            Integer secondOrder = second instanceof Ordered ? ((Ordered) second).getOrder() : 0;
            return firstOrder.compareTo(secondOrder);
        }
    });
    long time = System.nanoTime();
    for (SessionPostProcessor postProcessor : postProcessors) {
        if (postProcessor instanceof EntityContextAware) {
            ((EntityContextAware) postProcessor).setEntityContext(getEntityContext(beanFactory));
        }
        if (postProcessor instanceof TableMetadataRegistryAware) {
            ((TableMetadataRegistryAware) postProcessor)
                    .setTableMetadataRegistry(getTableMetadataRegistry(beanFactory));
        }
        if (postProcessor instanceof StatementRegistryAware) {
            ((StatementRegistryAware) postProcessor).setStatementRegistry(getStatementRegistry(beanFactory));
        }
        if (postProcessor instanceof DatabaseDialectAware) {
            ((DatabaseDialectAware) postProcessor).setDatabaseDialect(getDatabaseDialect(beanFactory));
        }
        postProcessor.postProcessSession(beanFactory);
    }
    time = System.nanoTime() - time;
    log.info("Session preparation took " + Math.round((double) time / 1000000d) / 1000d + " second(s)");
}

From source file:com.agileapes.couteau.context.spring.SpringContextConfigurator.java

@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    this.beanFactory = beanFactory;
    final Collection<SpringConfigurableContext> contexts = beanFactory
            .getBeansOfType(SpringConfigurableContext.class, false, true).values();
    for (SpringConfigurableContext context : contexts) {
        autoConfigure.add(context);//from  w ww  .j a  v a 2s . c o  m
    }
    if (!autoConfigure.isEmpty()) {
        for (Context<?> context : autoConfigure) {
            ContextConfigurator<Context<?>> configurator = ContextConfigurator.NULL;
            if (context instanceof SpringConfigurableContext<?>) {
                final SpringConfigurableContext<?> configurableContext = (SpringConfigurableContext<?>) context;
                configurator = new ContextConfigurator<Context<?>>() {
                    @Override
                    public void configure(Context<?> context, ConfigurableListableBeanFactory beanFactory) {
                        configurableContext.configure(beanFactory);
                    }
                };
            }
            try {
                configure(context, configurator);
            } catch (RegistryException e) {
                throw new FatalBeanException("Failed to configure context", e);
            }
        }
    }
}

From source file:com.mmnaseri.dragonfly.runtime.session.impl.AbstractSessionPreparator.java

@Override
public void postProcessSession(ConfigurableListableBeanFactory beanFactory) {
    log.warn(/*from ww w.j  a  v a2s. c o m*/
            "Preparing the session at runtime can be harmful to your performance. You should consider switching to "
                    + "the Maven plugin.");
    log.debug("Looking up the necessary components ...");
    if (parentClassLoader == null) {
        log.debug("Falling back to the application context class loader");
        parentClassLoader = beanFactory.getBeanClassLoader();
    }
    final DataAccessSession session = beanFactory.getBean(DataAccessSession.class);
    final Collection<SessionInitializationEventHandler> eventHandlers = beanFactory
            .getBeansOfType(SessionInitializationEventHandler.class, false, true).values();
    for (SessionInitializationEventHandler eventHandler : eventHandlers) {
        if (eventHandler instanceof DataAccessSessionAware) {
            DataAccessSessionAware aware = (DataAccessSessionAware) eventHandler;
            aware.setDataAccessSession(session);
        }
    }
    prepareResolvers(eventHandlers);
    registerEntities(eventHandlers);
    registerExtensions(eventHandlers);
    prepareStatements(eventHandlers);
    registerInterfaces(eventHandlers);
    initializeSession(session, beanFactory, eventHandlers);
    handleClassLoader(beanFactory);
}