Example usage for org.springframework.context.annotation AnnotationConfigApplicationContext refresh

List of usage examples for org.springframework.context.annotation AnnotationConfigApplicationContext refresh

Introduction

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

Prototype

@Override
    public void refresh() throws BeansException, IllegalStateException 

Source Link

Usage

From source file:org.finra.herd.tools.common.databridge.DataBridgeApp.java

/**
 * Creates and returns the Spring application context.
 *
 * @return the application context//w w w  .  j a  va2s .co m
 */
protected ApplicationContext createApplicationContext() {
    // Create the Spring application context and register the JavaConfig classes we need.
    // We will use core (in case it's needed), the service aspect that times the duration of the service method calls, and our specific beans defined in
    // the data bridge configuration. We're not including full service and DAO configurations because they come with database/data source dependencies
    // that we don't need and don't want (i.e. we don't want the database to be running as a pre-requisite for running the uploader).
    AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
    ApplicationContextHolder.setApplicationContext(applicationContext);
    applicationContext.register(CoreSpringModuleConfig.class, DataBridgeSpringModuleConfig.class,
            DataBridgeAopSpringModuleConfig.class, DataBridgeEnvSpringModuleConfig.class);
    applicationContext.refresh();
    return applicationContext;
}

From source file:org.finra.herd.tools.retention.destroyer.RetentionExpirationDestroyerApp.java

/**
 * Creates and returns the Spring application context.
 *
 * @return the application context//w  w w .  j  a v  a 2  s  .  c o  m
 */
private ApplicationContext createApplicationContext() {
    // Create the Spring application context and register the JavaConfig classes we need.
    // We will use core (in case it's needed), the service aspect that times the duration of the service method calls, and our specific beans defined in
    // the data bridge configuration. We're not including full service and DAO configurations because they come with database/data source dependencies
    // that we don't need and don't want (i.e. we don't want the database to be running as a pre-requisite for running the application).
    AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
    ApplicationContextHolder.setApplicationContext(applicationContext);
    applicationContext.register(CoreSpringModuleConfig.class, DataBridgeSpringModuleConfig.class,
            DataBridgeAopSpringModuleConfig.class, DataBridgeEnvSpringModuleConfig.class);
    applicationContext.refresh();
    return applicationContext;
}

From source file:org.springframework.boot.actuate.autoconfigure.metrics.PublicMetricsAutoConfigurationTests.java

private void load(Class<?>... config) {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    if (config.length > 0) {
        context.register(config);//from   w  ww  .j  av a 2  s .  c  o  m
    }
    context.register(DataSourcePoolMetadataProvidersConfiguration.class, CacheStatisticsAutoConfiguration.class,
            PublicMetricsAutoConfiguration.class);
    context.refresh();
    this.context = context;
}

From source file:org.springframework.boot.autoconfigure.AutoConfigurationReportLoggingInitializerTests.java

@Test
public void logsDebugOnContextRefresh() {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    this.initializer.initialize(context);
    context.register(Config.class);
    context.refresh();
    this.initializer.onApplicationEvent(new ContextRefreshedEvent(context));
    assertThat(this.debugLog.size(), not(equalTo(0)));
}

From source file:org.springframework.boot.autoconfigure.AutoConfigurationReportLoggingInitializerTests.java

@Test
public void logsInfoOnError() {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    this.initializer.initialize(context);
    context.register(ErrorConfig.class);
    try {/*from w  w  w . jav a  2s.co m*/
        context.refresh();
        fail("Did not error");
    } catch (Exception ex) {
        this.initializer.handleError(null, context, new String[] {}, ex);
    }

    assertThat(this.debugLog.size(), equalTo(0));
    assertThat(this.infoLog.size(), not(equalTo(0)));
}

From source file:org.springframework.boot.autoconfigure.AutoConfigurationReportLoggingInitializerTests.java

@Test
public void logsOutput() throws Exception {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    this.initializer.initialize(context);
    context.register(Config.class);
    context.refresh();
    this.initializer.onApplicationEvent(new ContextRefreshedEvent(context));
    for (String message : this.debugLog) {
        System.out.println(message);
    }//from   w  w  w  . ja va2 s  . c o  m
    // Just basic sanity check, test is for visual inspection
    String l = this.debugLog.get(0);
    assertThat(l, containsString("not a web application (OnWebApplicationCondition)"));
}

From source file:org.springframework.boot.autoconfigure.AutoConfigurationReportLoggingInitializerTests.java

@Test
public void canBeUsedInApplicationContext() throws Exception {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    context.register(Config.class);
    new AutoConfigurationReportLoggingInitializer().initialize(context);
    context.refresh();
    assertNotNull(context.getBean(AutoConfigurationReport.class));
}

From source file:org.springframework.boot.autoconfigure.logging.AutoConfigurationReportLoggingInitializerTests.java

@Test
public void logsDebugOnError() {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    this.initializer.initialize(context);
    context.register(ErrorConfig.class);
    try {//from  w w w .j  av a2 s.com
        context.refresh();
        fail("Did not error");
    } catch (Exception ex) {
        this.initializer.onApplicationEvent(
                new ApplicationFailedEvent(new SpringApplication(), new String[0], context, ex));
    }

    assertThat(this.debugLog.size(), not(equalTo(0)));
    assertThat(this.infoLog.size(), equalTo(0));
}

From source file:org.springframework.boot.autoconfigure.logging.AutoConfigurationReportLoggingInitializerTests.java

@Test
public void logsInfoOnErrorIfDebugDisabled() {
    setupLogging(false, true);//from   ww w  . j a  va 2s  . c om
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    this.initializer.initialize(context);
    context.register(ErrorConfig.class);
    try {
        context.refresh();
        fail("Did not error");
    } catch (Exception ex) {
        this.initializer.onApplicationEvent(
                new ApplicationFailedEvent(new SpringApplication(), new String[0], context, ex));
    }

    assertThat(this.debugLog.size(), equalTo(0));
    assertThat(this.infoLog.size(), not(equalTo(0)));
}

From source file:org.springframework.boot.autoconfigure.logging.AutoConfigurationReportLoggingInitializerTests.java

@Test
public void logsOutput() throws Exception {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    this.initializer.initialize(context);
    context.register(Config.class);
    ConditionEvaluationReport.get(context.getBeanFactory()).recordExclusions(Arrays.asList("com.foo.Bar"));
    context.refresh();
    this.initializer.onApplicationEvent(new ContextRefreshedEvent(context));
    for (String message : this.debugLog) {
        System.out.println(message);
    }//  w  ww .j  a  v a2s  .c  o m
    // Just basic sanity check, test is for visual inspection
    String l = this.debugLog.get(0);
    assertThat(l, containsString("not a web application (OnWebApplicationCondition)"));
}