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

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

Introduction

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

Prototype

public AnnotationConfigApplicationContext(String... basePackages) 

Source Link

Document

Create a new AnnotationConfigApplicationContext, scanning for bean definitions in the given packages and automatically refreshing the context.

Usage

From source file:org.jboss.narayana.quickstart.spring.Launch.java

public static void main(String[] args) throws Exception {
    AbstractApplicationContext context = new AnnotationConfigApplicationContext(
            Launch.class.getPackage().getName());
    ExampleService service = context.getBean(ExampleService.class);

    if (args.length == 1) {
        RecoveryManagerService recoveryManagerService = context.getBean(RecoveryManagerService.class);
        if (args[0].equals("-f")) {
            System.out.println("Generate something to recovery ...");
            service.testRecovery();/*from  w w  w .  j a v  a 2  s .  co  m*/
        } else if (args[0].equals("-r")) {
            System.out.println("start the recovery manager");
            recoveryManagerService.start();

            System.out.println("recovery manager scan ...");
            while (DummyXAResource.getCommitRequests() == 0) {
                Thread.sleep(1000);
            }

            System.out.println("stop the recovery manager");
            recoveryManagerService.stop();
        } else if (args[0].equals("-c")) {
            service.checkRecord();
        }
    } else {
        service.testCommit();
        service.checkRecord();
    }

    service.shutdownDatabase();
    TxControl.disable(true);
    TransactionReaper.terminate(true);
}

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

public static void main(String[] args) throws Throwable {
    try {//  w  w w  .  java2 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:com.doctor.ignite.example.spring.SqlUnion.java

public static void main(String[] args) throws InterruptedException {
    AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(
            SpringIgniteConfig.class);
    Ignite ignite = applicationContext.getBean(Ignite.class);

    CacheConfiguration<UUID, Person> cacheConfiguration = applicationContext
            .getBean("CacheConfigurationForDays", CacheConfiguration.class);

    IgniteCache<UUID, Person> igniteCache1 = getCache("person1", ignite, cacheConfiguration);

    Person person = new Person(UUID.randomUUID(), "doctor -1 ", BigDecimal.valueOf(88888888.888), "man", "...");
    igniteCache1.put(person.getId(), person);

    Person person1 = new Person(UUID.randomUUID(), "doctor 118", BigDecimal.valueOf(88888888.888), "man",
            "...");
    igniteCache1.put(person1.getId(), person1);

    Person person2 = new Person(UUID.randomUUID(), "doctor who 88 ", BigDecimal.valueOf(188888888.888), "man",
            "...");
    igniteCache1.put(person2.getId(), person2);

    IgniteCache<UUID, Person> igniteCache2 = getCache("person2", ignite, cacheConfiguration);

    Person person3 = new Person(UUID.randomUUID(), "doctor who ---88 ", BigDecimal.valueOf(1188888888.888),
            "man", "...");
    igniteCache2.put(person3.getId(), person3);

    SqlFieldsQuery sqlFieldsQuery = new SqlFieldsQuery(
            "select _val from Person  union all select _val from \"person2\".Person");

    try (QueryCursor queryCursor = igniteCache1.query(sqlFieldsQuery)) {
        for (Object object : queryCursor) {
            System.out.println(object);
        }//from  w  w  w .j  a v a2s .  co  m
    }

    applicationContext.close();
}

From source file:com.khartec.waltz.jobs.sample.CapabilityGenerator.java

public static void main(String[] args) throws IOException {

    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);

    List<String> lines = readLines(CapabilityGenerator.class.getResourceAsStream("/capabilities.csv"));

    System.out.println("Deleting existing Caps's");
    dsl.deleteFrom(CAPABILITY).execute();

    List<CapabilityRecord> records = lines.stream().skip(1).map(line -> line.split("\t"))
            .filter(cells -> cells.length == 4).map(cells -> {
                CapabilityRecord record = new CapabilityRecord();
                record.setId(longVal(cells[0]));
                record.setParentId(longVal(cells[1]));
                record.setName(cells[2]);
                record.setDescription(cells[3]);

                System.out.println(record);
                return record;
            }).collect(Collectors.toList());

    System.out.println("Inserting new Caps's");
    dsl.batchInsert(records).execute();/*from   w  w  w .  j  a v  a2s .co m*/

    System.out.println("Done");

}

From source file:com.khartec.waltz.jobs.CapabilityHarness.java

public static void main(String[] args) {

    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);

    DSLContext dsl = ctx.getBean(DSLContext.class);

    CapabilityDao dao = ctx.getBean(CapabilityDao.class);

    CapabilityIdSelectorFactory selectorFactory = ctx.getBean(CapabilityIdSelectorFactory.class);

    Select<Record1<Long>> selector = selectorFactory.apply(ImmutableIdSelectionOptions.builder()
            .entityReference(ImmutableEntityReference.builder().kind(EntityKind.APP_GROUP).id(5L).build())
            .scope(HierarchyQueryScope.PARENTS).build());

    Collection<Capability> caps = dao.findByIdSelector(selector);
    caps.forEach(c -> System.out.println(c.name()));

}

From source file:com.khartec.waltz.jobs.sample.UnknownFlowGenerator.java

public static void main(String[] args) {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);

    ApplicationService applicationDao = ctx.getBean(ApplicationService.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);

    List<Application> allApps = applicationDao.findAll();

    Set<DataFlowRecord> records = IntStream.range(0, 2000)
            .mapToObj(i -> Tuple.tuple(randomPick(allApps).id().get(), randomPick(allApps).id().get()))
            .map(t -> new DataFlowRecord("APPLICATION", t.v1(), "APPLICATION", t.v2(), "UNKNOWN", "UNK_TEST"))
            .collect(Collectors.toSet());

    dsl.deleteFrom(DATA_FLOW).where(DATA_FLOW.PROVENANCE.eq("UNK_TEST")).execute();

    dsl.batchInsert(records).execute();/*from  w  w  w  . j a v a  2 s .c om*/

    System.out.println("Done");
}

From source file:com.doctor.ignite.example.spring.SpringIgniteExample.java

public static void main(String[] args) throws InterruptedException {
    AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(
            SpringIgniteConfig.class);
    Ignite ignite = applicationContext.getBean(Ignite.class);

    CacheConfiguration<UUID, Person> cacheConfiguration = applicationContext
            .getBean("CacheConfigurationForDays", CacheConfiguration.class);

    IgniteCache<UUID, Person> igniteCache2 = ignite.cache("cacheForDays");

    if (igniteCache2 == null) {
        CacheConfiguration<UUID, Person> cacheConfiguration2 = new CacheConfiguration<>(cacheConfiguration);
        cacheConfiguration2.setName("cacheForDays");
        igniteCache2 = ignite.createCache(cacheConfiguration2);

        System.out.println("--------createCache:" + "cacheForDays");
    }//www . ja v a  2s  .c  o m

    Person person = new Person(UUID.randomUUID(), "doctor", BigDecimal.valueOf(88888888.888), "man", "...");
    System.out.println(igniteCache2.get(person.getId()));
    igniteCache2.put(person.getId(), person);
    System.out.println(igniteCache2.get(person.getId()));

    TimeUnit.SECONDS.sleep(6);
    System.out.println(igniteCache2.get(person.getId()));

    System.out.println("");
    Person person1 = new Person(UUID.randomUUID(), "doctor 118", BigDecimal.valueOf(88888888.888), "man",
            "...");
    igniteCache2.put(person1.getId(), person1);

    Person person2 = new Person(UUID.randomUUID(), "doctor who 88 ", BigDecimal.valueOf(188888888.888), "man",
            "...");
    igniteCache2.put(person2.getId(), person2);

    try (QueryCursor<List<?>> queryCursor = igniteCache2.query(new SqlFieldsQuery("select name from Person"))) {
        for (List<?> entry : queryCursor) {
            System.out.println(entry);
        }
    }

    applicationContext.close();
}

From source file:org.keyboardplaying.xtt.ConstructApplication.java

/**
 * Main method for the application.//www . j  av a 2s.c  o  m
 *
 * @param args
 *            unused arguments
 */
public static void main(String... args) {
    @SuppressWarnings("resource") // not closing, needed for prototypes
    ApplicationContext ctx = new AnnotationConfigApplicationContext(UIConfiguration.class);
    UIController controller = ctx.getBean(UIController.class);
    controller.startUI();
}

From source file:org.cyberjos.jcconf2014.SampleMain.java

/**
 * Main method./*  w ww .  j av a 2  s . c  o  m*/
 *
 * @param args arguments
 */
public static void main(final String[] args) {
    logger.info("Starting to launch application...");

    context = new AnnotationConfigApplicationContext(Application.class);
    final CloudNode cloudNode = context.getBean(CloudNode.class);

    context.registerShutdownHook();
    logger.info("The node has been started: {}", cloudNode.getName());
}

From source file:org.cyberjos.jcconf2016.HazelcastNodeMain.java

/**
 * Main method./*from  w w w .j  av a  2s  .c om*/
 *
 * @param args arguments
 */
public static void main(final String[] args) {
    logger.info("Starting to launch application...");

    context = new AnnotationConfigApplicationContext(Application.class);
    final CloudNode cloudNode = context.getBean(CloudNode.class);

    context.registerShutdownHook();
    if (cloudNode != null) {
        context.registerShutdownHook();
        logger.info("[{}] The node has been started.", cloudNode.getName());
    } else {
        logger.warn("There is NO node running!! Please check the argument.");
    }
}