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

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

Introduction

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

Prototype

@Override
    public void start() 

Source Link

Usage

From source file:example.helloworld.HelloWorldApplication.java

public static void main(String[] args) {

    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
            VaultConfiguration.class);

    context.start();

    VaultTemplate vaultTemplate = context.getBean(VaultTemplate.class);

    MySecretData mySecretData = new MySecretData();
    mySecretData.setUsername("walter");
    mySecretData.setPassword("white");

    vaultTemplate.write("secret/myapplication/user/3128", mySecretData);
    log.info("Wrote data to Vault");

    VaultResponseSupport<MySecretData> response = vaultTemplate.read("secret/myapplication/user/3128",
            MySecretData.class);

    log.info("Retrieved data {} from Vault", response.getData().getUsername());

    context.stop();/*  ww  w.jav  a 2 s.co  m*/
}

From source file:com.hotinno.feedmonitor.batch.Main.java

public static void main(String[] args) throws Throwable {
    try {/*from w  w  w. j  a v  a  2 s  .  c  om*/
        log.error("Entering batch...");

        String env = System.getenv("VCAP_SERVICES");
        log.error("************************************************************************");
        log.error("VCAP_SERVICES is: " + env);
        log.error("************************************************************************");

        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(
                BuffaloBatchConfiguration.class);

        org.apache.commons.dbcp.BasicDataSource ds = (org.apache.commons.dbcp.BasicDataSource) applicationContext
                .getBean("myDataSource");

        log.error(String.format("URL: %s", ds.getUrl()));
        log.error(String.format("Username: %s", ds.getUsername()));
        log.error(String.format("Password: %s", ds.getPassword()));

        applicationContext.start();

        log.error("Running...");
    } catch (Throwable t) {
        System.err.println(t);
        t.printStackTrace();
        log.error("Error occurred.", t);
    }
}

From source file:org.geosdi.geoplatform.experimental.dropwizard.app.CoreServiceApp.java

@Override
public void run(CoreServiceConfig t, Environment e) throws Exception {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.register(CoreOAuth2ServiceLoader.class);
    ctx.refresh();/*  ww  w. j av  a 2  s .c o  m*/
    ctx.registerShutdownHook();
    ctx.start();

    e.jersey().register(
            new JacksonMessageBodyProvider(new GPJacksonSupport().getDefaultMapper(), e.getValidator()));
    e.jersey().register(new OAuth2ExceptionProvider());
    e.jersey().register(new OAuthProvider<>(new CoreOAuthAuthenticator(t), "protected-resources"));
    e.healthChecks().register("service-health-check", new CoreServiceHealthCheck());

    Map<String, Object> resources = ctx.getBeansWithAnnotation(Path.class);

    for (Map.Entry<String, Object> entry : resources.entrySet()) {
        e.jersey().register(entry.getValue());
    }
}

From source file:fr.javatronic.damapping.test.injectable.SpringHotelControllerTest.java

@BeforeClass
public void setup() {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(
            SpringHotelControllerConfiguration.class);
    this.hotelController = ctx.getAutowireCapableBeanFactory().getBean(HotelController.class);
    ctx.start();
}

From source file:org.jacpfx.vertx.spring.SpringVerticleFactory.java

private Verticle createSpringVerticle(final Class<?> currentVerticleClass, ClassLoader classLoader) {
    final SpringVerticle annotation = currentVerticleClass.getAnnotation(SpringVerticle.class);
    final Class<?> springConfigClass = annotation.springConfig();

    // Create the parent context  
    final GenericApplicationContext genericApplicationContext = new GenericApplicationContext();
    genericApplicationContext.setClassLoader(classLoader);
    if (parentContext != null) {
        genericApplicationContext.setParent(parentContext);
    }// w  w  w .ja  va 2  s . c  om
    genericApplicationContext.refresh();
    genericApplicationContext.start();

    // 1. Create a new context for each verticle and use the specified spring configuration class if possible
    AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext();
    annotationConfigApplicationContext.setParent(genericApplicationContext);
    annotationConfigApplicationContext.register(SpringContextConfiguration.class, springConfigClass);

    // 2. Register a bean definition for this verticle
    annotationConfigApplicationContext.registerBeanDefinition(currentVerticleClass.getSimpleName(),
            new VerticleBeanDefinition(currentVerticleClass));

    // 3. Add a bean factory post processor to avoid configuration issues
    annotationConfigApplicationContext
            .addBeanFactoryPostProcessor(new SpringSingleVerticleConfiguration(currentVerticleClass));
    annotationConfigApplicationContext.refresh();
    annotationConfigApplicationContext.start();
    annotationConfigApplicationContext.registerShutdownHook();

    // 5. Return the verticle by fetching the bean from the context
    return (Verticle) annotationConfigApplicationContext.getBeanFactory()
            .getBean(currentVerticleClass.getSimpleName());
}