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

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

Introduction

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

Prototype

@Override
public void close() 

Source Link

Document

Close this application context, destroying all beans in its bean factory.

Usage

From source file:com.mine.cassandra.sink.CassandraSinkPropertiesTests.java

@Test
public void statementExpressionCanBeCustomized() {
    String queryDsl = "Select(FOO.BAR).From(FOO)";
    Expression expression = new SpelExpressionParser().parseExpression(queryDsl);
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    EnvironmentTestUtils.addEnvironment(context, "statement-expression:" + queryDsl);
    context.register(Conf.class);
    context.refresh();/* w w w .ja  v a 2 s  .c  o m*/
    CassandraSinkProperties properties = context.getBean(CassandraSinkProperties.class);
    assertThat(properties.getStatementExpression().getExpressionString(),
            equalTo(expression.getExpressionString()));
    context.close();
}

From source file:net.slkdev.swagger.confluence.gradle.plugin.SwaggerConfluenceGradleTask.java

@TaskAction
public void swaggerConfluence() {
    final AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext(
            SwaggerConfluenceContextConfig.class);
    final SwaggerToConfluenceService swaggerToConfluenceService = annotationConfigApplicationContext
            .getBean(SwaggerToConfluenceService.class);
    final SwaggerConfluenceConfig swaggerConfluenceConfig = getProject().getExtensions()
            .findByType(SwaggerConfluenceConfig.class);
    swaggerToConfluenceService.convertSwaggerToConfluence(swaggerConfluenceConfig);
    annotationConfigApplicationContext.close();
}

From source file:com.doctor.spring4.blog.code.WireObjectDependenciesOutsideSpring.java

/**
 * Instantiate the bean and then inject dependencies using AutoWireCapableBeanFactory.autowireBean(instance)
 *//*from www.  j  a v  a  2  s  .c o  m*/
@Test
public void test_only_inject_dependencies() {
    AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(
            SpringConfig.class);
    Person person = new Person();
    assertNull(person.getContext());
    applicationContext.getAutowireCapableBeanFactory().autowireBean(person);

    assertNotNull(person.getContext());
    Stream.of(applicationContext.getBeanDefinitionNames()).forEach(System.out::println);

    applicationContext.close();
}

From source file:com.doctor.spring4.blog.code.WireObjectDependenciesOutsideSpring.java

/**
 * Instantiate the bean and then inject dependencies using AutoWireCapableBeanFactory.autowireBean(instance)
 * beanperson??/*from ww  w . j  a  v  a 2s.c o  m*/
 */
@Test
public void test_create_bean_and_inject_dependencies() {
    AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(
            SpringConfig.class);
    Person person = (Person) applicationContext.getAutowireCapableBeanFactory().createBean(Person.class,
            AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false);

    assertNotNull(person.getContext());
    Stream.of(applicationContext.getBeanDefinitionNames()).forEach(System.out::println);
    applicationContext.close();
}

From source file:com.github.qwazer.markdown.confluence.gradle.plugin.ConfluenceGradleTask.java

@TaskAction
public void confluence() throws NoSuchAlgorithmException, KeyManagementException, IOException {
    final AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext(
            SpringConfig.class);
    final MainService mainService = annotationConfigApplicationContext.getBean(MainService.class);

    final ConfluenceConfig confluenceConfig = getProject().getExtensions().findByType(ConfluenceConfig.class);

    validate(confluenceConfig);/*from ww  w. j a v  a 2  s  .c  o  m*/

    if (confluenceConfig.isSslTrustAll()) {
        sslTrustAll();
    }

    mainService.processAll(confluenceConfig);
    annotationConfigApplicationContext.close();
}

From source file:org.jasypt.spring31.annotation.EncryptablePropertySourcePostProcessorTest.java

@Test
public void withUnresolvablePlaceholderAndDefault() {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.register(ConfigWithUnresolvablePlaceholderAndDefault.class);
    ctx.refresh();// www .j a va2s  .c  o  m
    assertThat(ctx.getBean(TestBean.class).getName(), equalTo("p1TestBean"));
    ctx.close();

}

From source file:com.doctor.spring4.blog.code.WireObjectDependenciesOutsideSpring.java

/**
 * ??spring??//from w w w. j  a v a2s.  c o m
 * 
 * @see http://www.javacodegeeks.com/2012/03/integrating-spring-into-legacy.html
 * 
 */
@Test
public void test_registerSingleton() {
    AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(
            SpringConfig.class);
    Person person = new Person();
    assertNull(person.getContext());

    applicationContext.getBeanFactory().registerSingleton("person", person);
    assertNotNull(applicationContext.getBean(Person.class));

    assertNull(person.getContext());

    applicationContext.getAutowireCapableBeanFactory().autowireBean(person);
    assertNotNull(person.getContext());
    Stream.of(applicationContext.getBeanDefinitionNames()).forEach(System.out::println);

    applicationContext.close();
}

From source file:org.jasypt.spring31.annotation.EncryptablePropertySourcePostProcessorTest.java

@Test
public void withEmptyResourceLocations() {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.register(ConfigWithEmptyResourceLocations.class);
    try {/*w  ww  .ja v a 2 s  .c om*/
        ctx.refresh();
    } catch (BeanCreationException ex) {
        assertTrue(ex.getCause() instanceof IllegalArgumentException);
    }
    ctx.close();

}

From source file:com.domingosuarez.boot.autoconfigure.jade4j.Jade4JAutoConfigurationTests.java

@Test
@Ignore//w  w  w . ja  v  a  2 s.  c o  m
public void renderNonWebAppTemplate() throws Exception {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
            Jade4JAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class);
    assertEquals(0, context.getBeanNamesForType(ViewResolver.class).length);
    try {
        JadeConfiguration engine = this.context.getBean(JadeConfiguration.class);
        JadeTemplate template = engine.getTemplate("demo.jade");
        Map<String, Object> params = params();
        String result = engine.renderTemplate(template, params);

        assertThat(result, containsString("With user"));
    } finally {
        context.close();
    }
}

From source file:org.jasypt.spring31.annotation.EncryptablePropertySourcePostProcessorTest.java

@Test
public void withUnresolvablePlaceholder() {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.register(ConfigWithUnresolvablePlaceholder.class);
    try {/*from   w  w  w.ja  v a2s.  com*/
        ctx.refresh();
    } catch (BeanCreationException ex) {
        assertTrue(ex.getCause() instanceof IllegalArgumentException);
    }
    ctx.close();

}