Package org.springframework.context.annotation

Examples of org.springframework.context.annotation.AnnotationConfigApplicationContext


    public ApplicationContext loadContext(String... locations) {
        if (logger.isDebugEnabled()) {
            logger.debug("Creating a JavaConfigApplicationContext for {}", Arrays.asList(locations));
        }

        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();

        ArrayList<Class<?>> configClasses = new ArrayList<Class<?>>();
        ArrayList<String> basePackages = new ArrayList<String>();
        for (String location : locations) {
            // if the location refers to a class, use it. Otherwise assume it's a base package name
            try {
                final Class<?> aClass = this.getClass().getClassLoader().loadClass(location);
                configClasses.add(aClass);
            } catch (ClassNotFoundException e) {
                if (Package.getPackage(location) == null) {
                    throw new IllegalArgumentException(
                            String.format("A non-existent class or package name was specified: [%s]", location));
                }
                basePackages.add(location);
            }
        }

        logger.debug("Setting config classes to {}", configClasses);
        logger.debug("Setting base packages to {}", basePackages);

        for (Class<?> configClass : configClasses) {
            context.register(configClass);
        }
       
        for (String basePackage : basePackages) {
            context.scan(basePackage);
        }
       
        context.refresh();

        // Have to create a child context that implements BeanDefinitionRegistry
        // to pass to registerAnnotationConfigProcessors, since
        // JavaConfigApplicationContext does not
        final GenericApplicationContext gac = new GenericApplicationContext(context);
        AnnotationConfigUtils.registerAnnotationConfigProcessors(gac);
        // copy BeanPostProcessors to the child context
        for (String bppName : context.getBeanFactory().getBeanNamesForType(BeanPostProcessor.class)) {
            gac.registerBeanDefinition(bppName, context.getBeanFactory().getBeanDefinition(bppName));
        }
        gac.refresh();
        gac.registerShutdownHook();

        return gac;
View Full Code Here


public class FacesFlowBuilderServicesJavaConfigTests extends AbstractFacesFlowBuilderServicesConfigurationTests {


  @Override
  protected ApplicationContext initApplicationContext() {
    return new AnnotationConfigApplicationContext(FacesFlowConfig.class);
  }
View Full Code Here

public class ResourcesJavaConfigTests extends AbstractResourcesConfigurationTests {


  @Override
  protected ApplicationContext initApplicationContext() {
    return new AnnotationConfigApplicationContext(FacesFlowConfig.class);
  }
View Full Code Here

    }

    @Override
    public void start(Stage stage) throws Exception {
        primaryStage = stage;
        ApplicationContext context = new AnnotationConfigApplicationContext(CustomerAppConfiguration.class);
        context.getBean(LoginDialogProvider.class).get().show();
    }
View Full Code Here

  }
 
  public static void main(String[] args)
  {
    // bootstrap spring by scanning for components linked to the SpiderController
    ApplicationContext ctx = new AnnotationConfigApplicationContext(SpiderController.class);

    // use our context to get access to the Spider component
    Spider webCrawler = (Spider) ctx.getBean(Spider.class);
   
    // the Spider components @Autowire annotation will automatically load the HttpClient and HttpParser @Components.
    webCrawler.startCrawl();
  }
View Full Code Here

import org.springframework.webflow.expression.spel.WebFlowSpringELExpressionParser;

public class FlowBuilderServicesJavaConfigTests extends AbstractFlowBuilderServicesConfigurationTests {

  protected ApplicationContext initApplicationContext() {
    return new AnnotationConfigApplicationContext(WebFlowConfig.class);
  }
View Full Code Here

*/
public class FlowExecutorJavaConfigTests extends AbstractFlowExecutorConfigurationTests {

  @Override
  protected ApplicationContext initApplicationContext() {
    return new AnnotationConfigApplicationContext(WebFlowConfig.class);
  }
View Full Code Here

import org.springframework.webflow.definition.registry.FlowDefinitionRegistry;

public class FlowDefinitionRegistryJavaConfigTests extends AbstractFlowRegistryConfigurationTests {

  protected ApplicationContext initApplicationContext() {
    return new AnnotationConfigApplicationContext(WebFlowConfig.class);
  }
View Full Code Here

        launch(args);
    }

    @Override
    public void start(Stage stage) throws Exception {
        ApplicationContext context = new AnnotationConfigApplicationContext(CustomerAppConfiguration.class);
        ScreensConfiguration screens = context.getBean(ScreensConfiguration.class);
        screens.setPrimaryStage(stage);
        screens.loginDialog().show();
    }
View Full Code Here

    public ApplicationContext loadContext(String... locations) {
        if (logger.isDebugEnabled()) {
            logger.debug("Creating a JavaConfigApplicationContext for {}", Arrays.asList(locations));
        }

        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();

        List<Class<?>> configClasses = new ArrayList<Class<?>>();
        List<String> basePackages = new ArrayList<String>();
        for (String location : locations) {
            // if the location refers to a class, use it. Otherwise assume it's a base package name
            try {
                final Class<?> aClass = this.getClass().getClassLoader().loadClass(location);
                configClasses.add(aClass);
            } catch (ClassNotFoundException e) {
                if (Package.getPackage(location) == null) {
                    throw new IllegalArgumentException(
                            String.format("A non-existent class or package name was specified: [%s]", location));
                }
                basePackages.add(location);
            }
        }

        logger.debug("Setting config classes to {}", configClasses);
        logger.debug("Setting base packages to {}", basePackages);

        for (Class<?> configClass : configClasses) {
            context.register(configClass);
        }
       
        for (String basePackage : basePackages) {
            context.scan(basePackage);
        }
       
        context.refresh();

        // Have to create a child context that implements BeanDefinitionRegistry
        // to pass to registerAnnotationConfigProcessors, since
        // JavaConfigApplicationContext does not
        final GenericApplicationContext gac = new GenericApplicationContext(context);
        AnnotationConfigUtils.registerAnnotationConfigProcessors(gac);
        // copy BeanPostProcessors to the child context
        for (String bppName : context.getBeanFactory().getBeanNamesForType(BeanPostProcessor.class)) {
            gac.registerBeanDefinition(bppName, context.getBeanFactory().getBeanDefinition(bppName));
        }
        gac.refresh();
        gac.registerShutdownHook();

        return gac;
View Full Code Here

TOP

Related Classes of org.springframework.context.annotation.AnnotationConfigApplicationContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.