Example usage for org.springframework.context.support AbstractApplicationContext getBeanNamesForType

List of usage examples for org.springframework.context.support AbstractApplicationContext getBeanNamesForType

Introduction

In this page you can find the example usage for org.springframework.context.support AbstractApplicationContext getBeanNamesForType.

Prototype

@Override
    public String[] getBeanNamesForType(@Nullable Class<?> type) 

Source Link

Usage

From source file:org.apache.camel.example.spring.javaconfig.IntegrationTest.java

@Test
public void testStartApplicationContext() throws Exception {
    // test to boot up the application context from spring configuration
    AbstractApplicationContext context = new ClassPathXmlApplicationContext(
            "/META-INF/spring/camel-context.xml");
    String[] names = context.getBeanNamesForType(CamelContext.class);
    assertEquals("There should be a camel context ", 1, names.length);
    CamelContext camelContext = context.getBean(names[0], CamelContext.class);
    assertNotNull(camelContext);/*from w  w  w  .  j  a  v  a  2  s  .com*/
    Thread.sleep(2000);

    // we're done so let's properly close the application context
    IOHelper.close(context);
}

From source file:org.trpr.platform.runtime.impl.container.spring.SpringContainerImpl.java

/**
 * Helper method that locates and loads all Bootstrap extensions
 *//*from   w  ww. ja v a  2s . com*/
private void initializeBootstrapExtensions() {
    File[] bootstrapExtensionFiles = FileLocator.findFiles(RuntimeConstants.BOOTSTRAP_EXTENSIONS_FILE);
    // Create the Bootstrap Extension dependency manager that will load all bootstrap extensions
    BootstrapExtensionDependencyManager beManager = new BootstrapExtensionDependencyManager(this);
    for (File beFile : bootstrapExtensionFiles) {
        try {
            // add the "file:" prefix to file names to get around strange behavior of FileSystemXmlApplicationContext that converts absolute path 
            // to relative path
            AbstractApplicationContext beDefinitionsContext = new FileSystemXmlApplicationContext(
                    FILE_PREFIX + beFile.getAbsolutePath());
            // All beans in the BE definitions context are expected to be of type BootstrapExtensionInfo. 
            // We look up and load only these to BootstrapExtensionDependencyManager
            String[] beInfos = beDefinitionsContext.getBeanNamesForType(BootstrapExtensionInfo.class);
            for (String beInfo : beInfos) {
                beManager.addBootstrapExtensionInfo(
                        (BootstrapExtensionInfo) beDefinitionsContext.getBean(beInfo));
            }
            // destroy the beDefinitionsContext as we dont need it anymore
            beDefinitionsContext.destroy();
        } catch (Exception e) {
            LOGGER.error("Error in loading BootStrap Extension File. Ignoring contents of : "
                    + beFile.getAbsolutePath() + " .Error message : " + e.getMessage(), e);
        }
    }
    this.bootstrapExtensions = (BootstrapExtension[]) beManager.loadBootstrapExtensions()
            .toArray(new BootstrapExtension[0]);
}