Example usage for org.springframework.context.annotation AnnotationConfigUtils CONFIGURATION_BEAN_NAME_GENERATOR

List of usage examples for org.springframework.context.annotation AnnotationConfigUtils CONFIGURATION_BEAN_NAME_GENERATOR

Introduction

In this page you can find the example usage for org.springframework.context.annotation AnnotationConfigUtils CONFIGURATION_BEAN_NAME_GENERATOR.

Prototype

String CONFIGURATION_BEAN_NAME_GENERATOR

To view the source code for org.springframework.context.annotation AnnotationConfigUtils CONFIGURATION_BEAN_NAME_GENERATOR.

Click Source Link

Document

The bean name of the internally managed BeanNameGenerator for use when processing Configuration classes.

Usage

From source file:org.elasticsoftware.elasticactors.spring.AnnotationConfigApplicationContext.java

/**
 * Provide a custom {@link BeanNameGenerator} for use with {@link AnnotatedBeanDefinitionReader}
 * and/or {@link ClassPathBeanDefinitionScanner}, if any.
 * <p>Default is {@link org.springframework.context.annotation.AnnotationBeanNameGenerator}.
 * <p>Any call to this method must occur prior to calls to {@link #register(Class...)}
 * and/or {@link #scan(String...)}.//www  . ja  v a2 s.  com
 * @see AnnotatedBeanDefinitionReader#setBeanNameGenerator
 * @see ClassPathBeanDefinitionScanner#setBeanNameGenerator
 */
public void setBeanNameGenerator(BeanNameGenerator beanNameGenerator) {
    this.reader.setBeanNameGenerator(beanNameGenerator);
    this.scanner.setBeanNameGenerator(beanNameGenerator);
    getBeanFactory().registerSingleton(AnnotationConfigUtils.CONFIGURATION_BEAN_NAME_GENERATOR,
            beanNameGenerator);
}

From source file:org.elasticsoftware.elasticactors.spring.AnnotationConfigWebApplicationContext.java

/**
 * Register a {@link org.springframework.beans.factory.config.BeanDefinition} for
 * any classes specified by {@link #register(Class...)} and scan any packages
 * specified by {@link #scan(String...)}.
 * <p>For any values specified by {@link #setConfigLocation(String)} or
 * {@link #setConfigLocations(String[])}, attempt first to load each location as a
 * class, registering a {@code BeanDefinition} if class loading is successful,
 * and if class loading fails (i.e. a {@code ClassNotFoundException} is raised),
 * assume the value is a package and attempt to scan it for annotated classes.
 * <p>Enables the default set of annotation configuration post processors, such that
 * {@code @Autowired}, {@code @Required}, and associated annotations can be used.
 * <p>Configuration class bean definitions are registered with generated bean
 * definition names unless the {@code value} attribute is provided to the stereotype
 * annotation.//ww w .  j  av  a  2  s  . c  o m
 * @see #register(Class...)
 * @see #scan(String...)
 * @see #setConfigLocation(String)
 * @see #setConfigLocations(String[])
 * @see AnnotatedBeanDefinitionReader
 * @see ClassPathBeanDefinitionScanner
 */
@Override
protected void loadBeanDefinitions(DefaultListableBeanFactory beanFactory) {
    AnnotatedBeanDefinitionReader reader = new AnnotatedBeanDefinitionReader(beanFactory);
    reader.setEnvironment(this.getEnvironment());

    ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(beanFactory);
    scanner.setEnvironment(this.getEnvironment());

    BeanNameGenerator beanNameGenerator = getBeanNameGenerator();
    ScopeMetadataResolver scopeMetadataResolver = getScopeMetadataResolver();
    if (beanNameGenerator != null) {
        reader.setBeanNameGenerator(beanNameGenerator);
        scanner.setBeanNameGenerator(beanNameGenerator);
        beanFactory.registerSingleton(AnnotationConfigUtils.CONFIGURATION_BEAN_NAME_GENERATOR,
                beanNameGenerator);
    }
    if (scopeMetadataResolver != null) {
        reader.setScopeMetadataResolver(scopeMetadataResolver);
        scanner.setScopeMetadataResolver(scopeMetadataResolver);
    }

    if (!this.annotatedClasses.isEmpty()) {
        if (logger.isInfoEnabled()) {
            logger.info("Registering annotated classes: ["
                    + StringUtils.collectionToCommaDelimitedString(this.annotatedClasses) + "]");
        }
        reader.register(this.annotatedClasses.toArray(new Class<?>[this.annotatedClasses.size()]));
    }

    if (!this.basePackages.isEmpty()) {
        if (logger.isInfoEnabled()) {
            logger.info("Scanning base packages: ["
                    + StringUtils.collectionToCommaDelimitedString(this.basePackages) + "]");
        }
        for (TypeFilter typeFilter : includeFilters) {
            scanner.addIncludeFilter(typeFilter);
        }
        scanner.scan(this.basePackages.toArray(new String[this.basePackages.size()]));
    }

    String[] configLocations = getConfigLocations();
    if (configLocations != null) {
        for (String configLocation : configLocations) {
            try {
                Class<?> clazz = getClassLoader().loadClass(configLocation);
                if (logger.isInfoEnabled()) {
                    logger.info("Successfully resolved class for [" + configLocation + "]");
                }
                reader.register(clazz);
            } catch (ClassNotFoundException ex) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Could not load class for config location [" + configLocation
                            + "] - trying package scan. " + ex);
                }
                int count = scanner.scan(configLocation);
                if (logger.isInfoEnabled()) {
                    if (count == 0) {
                        logger.info("No annotated classes found for specified class/package [" + configLocation
                                + "]");
                    } else {
                        logger.info(
                                "Found " + count + " annotated classes in package [" + configLocation + "]");
                    }
                }
            }
        }
    }
}

From source file:org.springframework.boot.SpringApplication.java

/**
 * Apply any relevant post processing the {@link ApplicationContext}. Subclasses can
 * apply additional processing as required.
 * @param context the application context
 *///w  w  w .  j  av  a 2  s . co  m
protected void postProcessApplicationContext(ConfigurableApplicationContext context) {
    if (this.webEnvironment) {
        if (context instanceof ConfigurableWebApplicationContext) {
            ConfigurableWebApplicationContext configurableContext = (ConfigurableWebApplicationContext) context;
            if (this.beanNameGenerator != null) {
                configurableContext.getBeanFactory().registerSingleton(
                        AnnotationConfigUtils.CONFIGURATION_BEAN_NAME_GENERATOR, this.beanNameGenerator);
            }
        }
    }

    if (this.resourceLoader != null) {
        if (context instanceof GenericApplicationContext) {
            ((GenericApplicationContext) context).setResourceLoader(this.resourceLoader);
        }
        if (context instanceof DefaultResourceLoader) {
            ((DefaultResourceLoader) context).setClassLoader(this.resourceLoader.getClassLoader());
        }
    }
}

From source file:org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext.java

/**
 * Provide a custom {@link BeanNameGenerator} for use with
 * {@link AnnotatedBeanDefinitionReader} and/or
 * {@link ClassPathBeanDefinitionScanner}, if any.
 * <p>/*from w  w w.  ja v a  2 s  .  c o  m*/
 * Default is
 * {@link org.springframework.context.annotation.AnnotationBeanNameGenerator}.
 * <p>
 * Any call to this method must occur prior to calls to {@link #register(Class...)}
 * and/or {@link #scan(String...)}.
 * @param beanNameGenerator the bean name generator
 * @see AnnotatedBeanDefinitionReader#setBeanNameGenerator
 * @see ClassPathBeanDefinitionScanner#setBeanNameGenerator
 */
public void setBeanNameGenerator(BeanNameGenerator beanNameGenerator) {
    this.reader.setBeanNameGenerator(beanNameGenerator);
    this.scanner.setBeanNameGenerator(beanNameGenerator);
    this.getBeanFactory().registerSingleton(AnnotationConfigUtils.CONFIGURATION_BEAN_NAME_GENERATOR,
            beanNameGenerator);
}