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

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

Introduction

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

Prototype

@Override
    public Object getBean(String name) throws BeansException 

Source Link

Usage

From source file:io.gravitee.reporter.elastic.ElasticsearchReporterTest.java

public void init() {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.register(ReporterConfiguration.class);
    ctx.refresh();/*from ww  w .j a  v  a2s . c  o  m*/
    this.reporter = ctx.getBean(ElasticsearchReporter.class);
}

From source file:com.github.jmnarloch.spring.jaxrs.client.jersey.JerseyClientConfigurationTest.java

/**
 * Tests the registration of the proxy factory in application context.
 *///from   w  w  w.  j  av a  2s .com
@Test
public void shouldRegisterClientProxyFactory() {

    // given
    final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
            JerseyClientConfiguration.class);

    // when
    JaxRsClientProxyFactory factory = context.getBean(JaxRsClientProxyFactory.class);

    // then
    assertNotNull(factory);
    assertTrue(JerseyClientProxyFactory.class.equals(factory.getClass()));
}

From source file:com.github.jmnarloch.spring.jaxrs.client.resteasy.RestEasyClientConfigurationTest.java

/**
 * Tests the registration of the proxy factory in application context.
 *///from ww w  .  ja  v a 2  s. c  o  m
@Test
public void shouldRegisterClientProxyFactory() {

    // given
    final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
            RestEasyClientConfiguration.class);

    // when
    JaxRsClientProxyFactory factory = context.getBean(JaxRsClientProxyFactory.class);

    // then
    assertNotNull(factory);
    assertTrue(RestEasyClientProxyFactory.class.equals(factory.getClass()));
}

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.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   w  w  w  .ja va 2 s.co m

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

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

From source file:nats.client.spring.JavaConfigAnnotationConfigTest.java

@Test
public void subscribeAnnotation() {
    final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
            AnnotationConfig.class);
    try {/*from  w  w w .  ja v  a2 s.com*/
        final Nats nats = context.getBean(Nats.class);
        testNatsConfig(context, nats);
    } finally {
        context.close();
    }
}

From source file:net.ggtools.maven.DDLGeneratorMojo.java

public void execute() throws MojoExecutionException {
    AnnotationConfigApplicationContext applicationContext = null;

    try {//ww w . j a va2 s  . c o m
        applicationContext = createApplicationContext();
        final DDLGenerator generator = applicationContext.getBean(DDLGenerator.class);
        getLog().info("Creating schema to " + ddlFile);
        generator.createSchema();
    } finally {
        if (applicationContext != null) {
            applicationContext.destroy();
        }
    }
}

From source file:org.springframework.data.web.config.SpringDataWebConfigurationIntegrationTests.java

private SpringDataWebConfiguration createConfigWithClassLoader(ClassLoader classLoader) {

    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
            SpringDataWebConfiguration.class);

    context.setClassLoader(classLoader);

    try {//w ww. j av  a2  s  . c o m
        return context.getBean(SpringDataWebConfiguration.class);
    } finally {
        context.close();
    }
}

From source file:nats.client.spring.JavaConfigAnnotationConfigTest.java

private void testNatsConfig(AnnotationConfigApplicationContext context, Nats nats) {
    assertNotNull(nats);/*from   ww w . ja  va  2s  .c o m*/

    final String body = "Java config is cool.";
    nats.publish("test", body);

    final SubscribeBean subscribeBean = context.getBean(SubscribeBean.class);

    assertEquals(subscribeBean.messages.size(), 1);
    assertEquals(body, subscribeBean.messages.get(0).getBodyAsString());
}

From source file:com.bank.config.code.IntegrationTests.java

@Test
public void transferTenDollars() throws InsufficientFundsException {

    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.getEnvironment().setDefaultProfiles("dev");
    ctx.register(TransferServiceConfig.class, StandaloneDataConfig.class, JndiDataConfig.class);
    ctx.refresh();/*from   w  w  w.  j  ava 2s . c o  m*/

    TransferService transferService = ctx.getBean(TransferService.class);
    AccountRepository accountRepository = ctx.getBean(AccountRepository.class);

    assertThat(accountRepository.findById("A123").getBalance(), equalTo(100.00));
    assertThat(accountRepository.findById("C456").getBalance(), equalTo(0.00));

    transferService.transfer(10.00, "A123", "C456");

    assertThat(accountRepository.findById("A123").getBalance(), equalTo(90.00));
    assertThat(accountRepository.findById("C456").getBalance(), equalTo(10.00));
}