Example usage for org.springframework.context.annotation AnnotatedBeanDefinitionReader AnnotatedBeanDefinitionReader

List of usage examples for org.springframework.context.annotation AnnotatedBeanDefinitionReader AnnotatedBeanDefinitionReader

Introduction

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

Prototype

public AnnotatedBeanDefinitionReader(BeanDefinitionRegistry registry) 

Source Link

Document

Create a new AnnotatedBeanDefinitionReader for the given registry.

Usage

From source file:org.anarres.dblx.core.Main.java

public static void main(String[] args) throws Exception {
    Stopwatch stopwatch = Stopwatch.createStarted();
    Arguments arguments = new Arguments(args);
    GenericApplicationContext context = new GenericApplicationContext();
    AnnotatedBeanDefinitionReader reader = new AnnotatedBeanDefinitionReader(context);
    reader.register(AppConfiguration.class);
    for (AppConfiguration.Provider configurationProvider : ServiceLoader
            .load(AppConfiguration.Provider.class)) {
        for (Class<?> configurationClass : configurationProvider.getConfigurationClasses()) {
            LOG.debug("Registering additional ServerConfiguration class " + configurationClass.getName());
            reader.register(configurationClass);
        }/*w  w w . jav a2 s . c  o  m*/
    }
    SpringUtils.addConfigurations(context, arguments);
    context.refresh();
    context.registerShutdownHook();
    context.start();

    LOG.info("Ready; startup took " + stopwatch);
}

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

/**
 * Create a new AnnotationConfigApplicationContext that needs to be populated
 * through {@link #register} calls and then manually {@linkplain #refresh refreshed}.
 *//* ww  w  .j a va 2  s.c o  m*/
public AnnotationConfigApplicationContext() {
    this.reader = new AnnotatedBeanDefinitionReader(this);
    this.scanner = new ClassPathBeanDefinitionScanner(this);
}

From source file:com.example.springsecurity.web.controllers.GenericWebContextLoader.java

protected void loadBeanDefinitions(GenericWebApplicationContext context,
        MergedContextConfiguration mergedConfig) {
    new AnnotatedBeanDefinitionReader(context).register(mergedConfig.getClasses());
    loadBeanDefinitions(context, mergedConfig.getLocations());
}

From source file:io.cloudslang.schema.EngineBeanDefinitionParser.java

private void loadContexts(Element element, BeanDefinitionRegistry beanDefinitionRegistry) {
    String externalDatabase = element.getAttribute("externalDatabase");
    if (StringUtils.isBlank(externalDatabase) || externalDatabase.equals(Boolean.FALSE.toString())) {
        AnnotatedBeanDefinitionReader definitionReader = new AnnotatedBeanDefinitionReader(
                beanDefinitionRegistry);
        definitionReader.register(ScoreDefaultDatasourceContext.class);
        definitionReader.register(ScoreDatabaseContext.class);
    }/*from w  w w  .  j a  va  2 s  .c om*/

    String repositoriesContextPath = "META-INF/spring/score/context/scoreRepositoryContext.xml";

    String ignoreEngineJobs = element.getAttribute("ignoreEngineJobs");
    if (StringUtils.isNotBlank(ignoreEngineJobs) && ignoreEngineJobs.equals(Boolean.TRUE.toString())) {
        new XmlBeanDefinitionReader(beanDefinitionRegistry).loadBeanDefinitions(repositoriesContextPath);
    } else {
        new XmlBeanDefinitionReader(beanDefinitionRegistry).loadBeanDefinitions(repositoriesContextPath,
                ENGINE_JOBS_CONTEXT_LOCATION);
    }
}

From source file:com.geodevv.testing.irmina.IrminaContextLoader.java

protected void loadBeanDefinitions(IrminaApplicationContext context, MergedContextConfiguration mergedConfig) {
    Class<?>[] configClasses = mergedConfig.getClasses();
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Registering configuration classes: " + ObjectUtils.nullSafeToString(configClasses));
    }//from ww  w .ja v  a  2  s  .  com
    new AnnotatedBeanDefinitionReader(context).register(configClasses);
}

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.//  w  ww.ja  v a2s. 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.web.servlet.context.AnnotationConfigServletWebServerApplicationContext.java

/**
 * Create a new {@link AnnotationConfigServletWebServerApplicationContext} that needs
 * to be populated through {@link #register} calls and then manually
 * {@linkplain #refresh refreshed}.//from   w  w w.  j  av  a2  s .c o m
 */
public AnnotationConfigServletWebServerApplicationContext() {
    this.reader = new AnnotatedBeanDefinitionReader(this);
    this.scanner = new ClassPathBeanDefinitionScanner(this);
}

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

/**
 * Create a new {@link AnnotationConfigServletWebServerApplicationContext} with the
 * given {@code DefaultListableBeanFactory}. The context needs to be populated through
 * {@link #register} calls and then manually {@linkplain #refresh refreshed}.
 * @param beanFactory the DefaultListableBeanFactory instance to use for this context
 *///from   w w w  . j a va 2s  .c  o m
public AnnotationConfigServletWebServerApplicationContext(DefaultListableBeanFactory beanFactory) {
    super(beanFactory);
    this.reader = new AnnotatedBeanDefinitionReader(this);
    this.scanner = new ClassPathBeanDefinitionScanner(this);
}

From source file:org.springframework.test.context.support.AnnotationConfigContextLoader.java

/**
 * Register classes in the supplied {@link GenericApplicationContext context}
 * from the classes in the supplied {@link MergedContextConfiguration}.
 * <p>Each class must represent an <em>annotated class</em>. An
 * {@link AnnotatedBeanDefinitionReader} is used to register the appropriate
 * bean definitions.//from  ww w . ja va2s. c om
 * <p>Note that this method does not call {@link #createBeanDefinitionReader}
 * since {@code AnnotatedBeanDefinitionReader} is not an instance of
 * {@link BeanDefinitionReader}.
 * @param context the context in which the annotated classes should be registered
 * @param mergedConfig the merged configuration from which the classes should be retrieved
 * @see AbstractGenericContextLoader#loadBeanDefinitions
 */
@Override
protected void loadBeanDefinitions(GenericApplicationContext context, MergedContextConfiguration mergedConfig) {
    Class<?>[] annotatedClasses = mergedConfig.getClasses();
    if (logger.isDebugEnabled()) {
        logger.debug("Registering annotated classes: " + ObjectUtils.nullSafeToString(annotatedClasses));
    }
    new AnnotatedBeanDefinitionReader(context).register(annotatedClasses);
}

From source file:org.springframework.test.context.support.AnnotationConfigWebContextLoader.java

/**
 * Register classes in the supplied {@link GenericWebApplicationContext context}
 * from the classes in the supplied {@link WebMergedContextConfiguration}.
 *
 * <p>Each class must represent an <em>annotated class</em>. An
 * {@link AnnotatedBeanDefinitionReader} is used to register the appropriate
 * bean definitions./*w  w w. j  a v  a2  s.  c o m*/
 *
 * @param context the context in which the annotated classes should be registered
 * @param webMergedConfig the merged configuration from which the classes should be retrieved
 *
 * @see AbstractGenericWebContextLoader#loadBeanDefinitions
 */
@Override
protected void loadBeanDefinitions(GenericWebApplicationContext context,
        WebMergedContextConfiguration webMergedConfig) {
    Class<?>[] annotatedClasses = webMergedConfig.getClasses();
    if (logger.isDebugEnabled()) {
        logger.debug("Registering annotated classes: " + ObjectUtils.nullSafeToString(annotatedClasses));
    }
    new AnnotatedBeanDefinitionReader(context).register(annotatedClasses);
}