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.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);
        }/*  w  w  w .  j  ava2 s . c o m*/
    }

    applicationContext.close();
}

From source file:com.iluwatar.repository.AppConfig.java

/**
 * Program entry point//from  ww  w  . j ava  2 s.co  m
 * 
 * @param args
 *          command line args
 */
public static void main(String[] args) {

    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);
    PersonRepository repository = context.getBean(PersonRepository.class);

    Person peter = new Person("Peter", "Sagan", 17);
    Person nasta = new Person("Nasta", "Kuzminova", 25);
    Person john = new Person("John", "lawrence", 35);
    Person terry = new Person("Terry", "Law", 36);

    // Add new Person records
    repository.save(peter);
    repository.save(nasta);
    repository.save(john);
    repository.save(terry);

    // Count Person records
    System.out.println("Count Person records: " + repository.count());

    // Print all records
    List<Person> persons = (List<Person>) repository.findAll();
    for (Person person : persons) {
        System.out.println(person);
    }

    // Update Person
    nasta.setName("Barbora");
    nasta.setSurname("Spotakova");
    repository.save(nasta);

    System.out.println("Find by id 2: " + repository.findOne(2L));

    // Remove record from Person
    repository.delete(2L);

    // count records
    System.out.println("Count Person records: " + repository.count());

    // find by name
    Person p = repository.findOne(new PersonSpecifications.NameEqualSpec("John"));
    System.out.println("Find by John is " + p);

    // find by age
    persons = repository.findAll(new PersonSpecifications.AgeBetweenSpec(20, 40));

    System.out.println("Find Person with age between 20,40: ");
    for (Person person : persons) {
        System.out.println(person);
    }

    context.close();

}

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");
    }/*  ww w  . j  av  a  2 s.  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:com.doctor.ignite.example.spring.CrossCacheQueries.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);

    // try (QueryCursor<List<?>> queryCursor = igniteCache1.query(new SqlFieldsQuery("select name from Person"))) {
    // for (List<?> entry : queryCursor) {
    // System.out.println("--}}}}}" + entry);
    // }/*from  www  .j ava2s. co m*/
    // }

    SqlQuery sqlQuery = new SqlQuery<>(Person.class, "from Person , \"person2\".Person  ");
    try (QueryCursor queryCursor = igniteCache1.query(sqlQuery)) {
        for (Object object : queryCursor) {
            System.out.println(object);
        }
    }

    applicationContext.close();
}

From source file:io.lavagna.loader.Loader.java

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

    System.setProperty("datasource.dialect", "MYSQL");

    AnnotationConfigApplicationContext ac = new AnnotationConfigApplicationContext(TestServiceConfig.class,
            PersistenceAndServiceConfig.class);

    ac.register(CreateCardService.class);

    ProjectService ps = ac.getBean(ProjectService.class);
    CreateCardService ccs = ac.getBean(CreateCardService.class);

    UserRepository ur = ac.getBean(UserRepository.class);
    List<User> users = new ArrayList<>();

    System.out.println("creating users");
    for (int i = 0; i < 30; i++) {
        ur.createUser("loader", "user" + i, null, null, true);
        users.add(ur.findUserByName("loader", "user" + i));
    }/*from   w w w  . j  ava2s  . c  o  m*/
    System.out.println("end creation");

    CardLabelRepository clr = ac.getBean(CardLabelRepository.class);

    List<Project> projects = new ArrayList<>(PROJECT_NUMBERS);
    List<Integer> milestonesIds = new ArrayList<>();
    System.out.println("creating projects");
    for (int i = 0; i < PROJECT_NUMBERS; i++) {
        String name = "Load test project " + i;
        Project p = ps.create(name, "LDTEST_" + i, name);
        projects.add(p);

        // create user labels
        for (int iLabel = 0; iLabel < 10; iLabel++) {
            clr.addLabel(p.getId(), true, LabelType.NULL, LabelDomain.USER, "label-" + iLabel, 0);
        }

        // update milestone label
        CardLabel milestoneLabel = clr.findLabelByName(p.getId(), "MILESTONE", LabelDomain.SYSTEM);
        for (int j = 0; j < MILESTONES_PER_PROJECT; j++) {
            milestonesIds.add(clr.addLabelListValue(milestoneLabel.getId(), Integer.toString(j)).getId());
        }
    }
    System.out.println("end creation");

    System.out.println("creating boards");
    for (Project project : projects) {
        buildBoards(project, ac, users, milestonesIds);
    }
    System.out.println("end creation");

    long processed = ccs.getCreatedCardCounter().get();
    while (!executor.awaitTermination(10, TimeUnit.SECONDS)) {
        long current = ccs.getCreatedCardCounter().get();
        System.err.println("processed: " + (current - processed) + " cards in 10s");
        processed = current;
    }

    ac.close();
}

From source file:pieShareAppITs.helper.ITUtil.java

public static void performTearDown(AnnotationConfigApplicationContext context) throws Exception {
    //shutdown application
    PieShareService service = context.getBean(PieShareService.class);
    context.close();
    service.stop();/*from   w  w  w  .j a va  2  s.  c o  m*/

    //get dirs to delete
    /*PieShareConfiguration config = context.getBean("pieUser", PieUser.class).getPieShareConfiguration();
    File mainWorkingDir = config.getWorkingDir();//config.getWorkingDirectory();
    File mainTmpDir = config.getTmpDir();
    File configMain = config.getPwdFile();
    config = context.getBean("botPieUser", PieUser.class).getPieShareConfiguration();
    File botWorkingDir = config.getWorkingDir();
    File botTmpDir = config.getTmpDir();
    File configBot = config.getPwdFile();*/

    //stop context
    //      context.close();
    context = null;
}

From source file:net.slkdev.swagger.confluence.cli.SwaggerConfluence.java

private static SwaggerToConfluenceService bootSwaggerConfluence() {
    final AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext(
            SwaggerConfluenceContextConfig.class);
    final SwaggerToConfluenceService swaggerToConfluenceService = annotationConfigApplicationContext
            .getBean(SwaggerToConfluenceService.class);
    annotationConfigApplicationContext.close();

    return swaggerToConfluenceService;
}

From source file:com.kurento.kmf.spring.KurentoApplicationContextUtils.java

public static void closeAllKurentoApplicationContexts(ServletContext ctx) {
    Assert.notNull(ctx, "Cannot close contexts from a null ServletContext");

    if (childContexts != null) {
        for (AnnotationConfigApplicationContext childContext : childContexts.values()) {
            log.info("Closing Kurento Servlet Application Context " + childContext);
            childContext.close();
        }//from  w w  w.j a va  2 s  .c  om
    }
    childContexts = null;

    if (kurentoApplicationContextInternalReference != null) {
        log.info("Closing Kurento Application Context " + kurentoApplicationContextInternalReference);
        kurentoApplicationContextInternalReference.close();
    }
    kurentoApplicationContextInternalReference = null;
}

From source file:com.netflix.genie.web.security.SecurityConditionsUnitTests.java

/**
 * Test to make sure that when no supported security is enabled the class doesn't fire.
 *
 * @throws Exception on any error/*from   w  w  w  .j  ava  2 s.co  m*/
 */
@Test
public void cantEnableBeanWithoutAnySecurityEnabled() throws Exception {
    final AnnotationConfigApplicationContext context = this.load(SecurityEnabled.class);
    Assert.assertFalse(context.containsBean("myBean"));
    context.close();
}

From source file:org.smartfrog.services.anubis.PartitionTest.java

@Override
protected void tearDown() throws Exception {
    if (controllerContext != null) {
        try {//from w w w.  ja va2 s  .  c om
            controllerContext.close();
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }
    controllerContext = null;
    if (memberContexts != null) {
        for (AnnotationConfigApplicationContext context : memberContexts) {
            try {
                context.close();
            } catch (Throwable e) {
                e.printStackTrace();
            }
        }
    }
    memberContexts = null;
    controller = null;
    partition = null;
    initialLatch = null;
}