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

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

Introduction

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

Prototype

public void register(Class<?>... annotatedClasses) 

Source Link

Document

Register one or more annotated classes to be processed.

Usage

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();/* w w  w .  ja  v a  2 s.com*/
    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.j  a va  2 s .com
        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();/*from www.j a v a 2  s  . c o m*/
    this.initializer.onApplicationEvent(new ContextRefreshedEvent(context));
    for (String message : this.debugLog) {
        System.out.println(message);
    }
    // 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();/*from  w w w . j  ava 2s.com*/
    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 {//w  w  w . j  a v a  2  s  . co m
        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);// ww w .ja  v  a2 s.  c  o m
    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();/*from w  w  w .  ja  va  2 s. c o m*/
    this.initializer.onApplicationEvent(new ContextRefreshedEvent(context));
    for (String message : this.debugLog) {
        System.out.println(message);
    }
    // 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.logging.AutoConfigurationReportLoggingInitializerTests.java

@Test
public void canBeUsedInApplicationContext() throws Exception {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    context.register(Config.class);
    new AutoConfigurationReportLoggingInitializer().initialize(context);
    context.refresh();//from ww  w . j  av  a  2s.c o m
    assertNotNull(context.getBean(ConditionEvaluationReport.class));
}

From source file:org.springframework.cloud.gateway.test.websocket.WebSocketIntegrationTests.java

private HttpHandler createHttpHandler() {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    context.register(WebSocketTestConfig.class);
    context.refresh();// w  w w  .  ja v  a  2s .c  om
    return WebHttpHandlerBuilder.applicationContext(context).build();
}

From source file:org.springframework.data.gemfire.support.SpringContextBootstrappingInitializer.java

/**
 * Registers the given Spring annotated (@Configuration) POJO classes with the specified
 * AnnotationConfigApplicationContext./*from www .j  a  va  2 s  . com*/
 *
 * @param applicationContext the AnnotationConfigApplicationContext used to register the Spring annotated,
 * POJO classes.
 * @param annotatedClasses a Class array of Spring annotated (@Configuration) classes used to configure
 * and initialize the Spring AnnotationConfigApplicationContext.
 * @return the given AnnotationConfigApplicationContext.
 * @see org.springframework.context.annotation.AnnotationConfigApplicationContext#register(Class[])
 */
AnnotationConfigApplicationContext registerAnnotatedClasses(
        AnnotationConfigApplicationContext applicationContext, Class<?>[] annotatedClasses) {
    if (!ObjectUtils.isEmpty(annotatedClasses)) {
        applicationContext.register(annotatedClasses);
    }

    return applicationContext;
}