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:org.sansdemeure.zenindex.main.Main.java

public static void main(String[] args) {

    Instant start = Instant.now();

    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.register(ServiceConfig.class);
    ctx.refresh();//ww  w  .  j  a  v  a  2 s. c om

    BatchService batch = (BatchService) ctx.getBean("batchService");
    batch.start(new File(args[0]));

    ctx.close();

    Instant end = Instant.now();
    logger.info("Duration of batch {}", Duration.between(start, end));

}

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

public static void main(String[] args) {

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

    dsl.delete(SERVER_INFORMATION).where(SERVER_INFORMATION.PROVENANCE.eq("RANDOM_GENERATOR")).execute();

    List<ServerInformation> servers = ListUtilities.newArrayList();

    IntStream/*from w  w w . j  a v a 2 s. co m*/
            .range(0,
                    10_000)
            .forEach(
                    i -> servers
                            .add(ImmutableServerInformation.builder().hostname(mkHostName(i))
                                    .environment(randomPick(SampleData.environments))
                                    .location(randomPick(SampleData.locations))
                                    .operatingSystem(randomPick(SampleData.operatingSystems))
                                    .operatingSystemVersion(randomPick(SampleData.operatingSystemVersions))
                                    .country(
                                            "UK")
                                    .assetCode(
                                            "wltz-0" + rnd.nextInt(4000))
                                    .hardwareEndOfLifeDate(rnd.nextInt(10) > 5
                                            ? Date.valueOf(
                                                    LocalDate.now().plusMonths(rnd.nextInt(12 * 6) - (12 * 3)))
                                            : null)
                                    .operatingSystemEndOfLifeDate(rnd.nextInt(10) > 5
                                            ? Date.valueOf(
                                                    LocalDate.now().plusMonths(rnd.nextInt(12 * 6) - (12 * 3)))
                                            : null)
                                    .virtual(rnd.nextInt(10) > 7).provenance("RANDOM_GENERATOR").build()));

    // servers.forEach(System.out::println);
    serverDao.bulkSave(servers);

}

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

public static void main(String[] args) {

    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    ServerInformationService serverInfoService = ctx.getBean(ServerInformationService.class);
    ServerInformationDao serverInfoDao = ctx.getBean(ServerInformationDao.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);

    IdSelectionOptions options = ImmutableIdSelectionOptions.builder()
            .entityReference(ImmutableEntityReference.builder().kind(EntityKind.ORG_UNIT).id(10).build())
            .scope(HierarchyQueryScope.CHILDREN).build();

    for (int i = 0; i < 5; i++) {
        HarnessUtilities.time("stats", () -> serverInfoService.findStatsForAppSelector(options));
    }/* w w  w.ja  v a2s. co m*/

    String sql = "\n" + "select \n" + "  coalesce(\n"
            + "    sum(case [server_information].[is_virtual] when 1 then 1\n"
            + "                                               else 0\n" + "        end), \n"
            + "    0) [virtual_count], \n" + "  coalesce(\n"
            + "    sum(case [server_information].[is_virtual] when 1 then 0\n"
            + "                                               else 1\n" + "        end), \n"
            + "    0) [physical_count]\n" + "from [server_information]\n"
            + "where [server_information].[asset_code] in (\n" + "  select [application].[asset_code]\n"
            + "  from [application]\n" + "  where [application].[id] in (\n" + "    select [application].[id]\n"
            + "    from [application]\n" + "    where [application].[organisational_unit_id] in (\n"
            + "      130, 260, 70, 200, 10, 140, 270, 80, 210, 20, 150, 280, 90, 220, 30, 160, \n"
            + "      290, 100, 230, 40, 170, 300, 110, 240, 50, 180, 120, 250, 60, 190\n" + "    )\n" + "  )\n"
            + ");\n";

    FunctionUtilities.time("raw q", () -> {
        dsl.connection(conn -> {
            PreparedStatement stmt = conn.prepareStatement(sql);
            ResultSet rs = stmt.executeQuery();
            while (rs.next()) {
                System.out.println(rs.getBigDecimal(1) + " - " + rs.getBigDecimal(2));
            }
        });
        return null;
    });

}

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

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

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

    EndUserAppService endUserService = ctx.getBean(EndUserAppService.class);

    List<Long> ids = IdUtilities.toIds(organisationalUnitDao.findAll());

    String[] subjects = { "Trade", "Risk", "Balance", "PnL", "Rate", "Fines", "Party", "Confirmations",
            "Settlement", "Instruction", "Person", "Profit", "Margin", "Finance", "Account" };

    String[] types = { "Report", "Summary", "Draft", "Calculations", "Breaks", "Record", "Statement",
            "Information", "Pivot" };

    String[] tech = { "MS ACCESS", "MS EXCEL", "VBA" };

    dsl.delete(END_USER_APPLICATION).execute();
    final Long[] idCounter = { 1L };
    ids.forEach(ouId -> {/*from w w  w.ja  v  a 2  s  .c  om*/
        for (int i = 0; i < new Random().nextInt(100) + 40; i++) {
            EndUserApplicationRecord record = dsl.newRecord(END_USER_APPLICATION);
            String name = new StringBuilder().append(randomPick(subjects)).append(" ")
                    .append(randomPick(subjects)).append(" ").append(randomPick(types)).append(" ")
                    .append(randomPick(types)).toString();

            record.setName(name);
            record.setDescription("About the " + name + " End user app");
            record.setKind(randomPick(tech));
            record.setRiskRating(randomPick(RiskRating.values()).name());
            record.setLifecyclePhase(randomPick(LifecyclePhase.values()).name());
            record.setOrganisationalUnitId(ouId);

            record.setId(idCounter[0]++);
            record.insert();
        }
    });

}

From source file:org.jmangos.auth.AuthServer.java

/**
 * The main method./* ww  w .jav  a 2 s.c  o  m*/
 * 
 * @param args
 *            the arguments
 * @throws Exception
 *             the exception
 */
public static void main(final String[] args) throws Exception {

    final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    context.scan("org.jmangos.commons", "org.jmangos.auth");
    context.refresh();
    ServiceContent.setContext(context);
    context.getBean(NetworkService.class).start();
}

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.  j  a v a  2s.  co  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.khartec.waltz.jobs.AuthSourceHarness.java

public static void main(String[] args) {

    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    AuthoritativeSourceCalculator authoritativeSourceCalculator = ctx
            .getBean(AuthoritativeSourceCalculator.class);

    long CTO_OFFICE = 40;
    long CTO_ADMIN = 400;
    long CEO_OFFICE = 10;
    long CIO_OFFICE = 20;
    long MARKET_RISK = 220;
    long CREDIT_RISK = 230;
    long OPERATIONS_IT = 200;
    long RISK = 210;

    long orgUnitId = CIO_OFFICE;

    authoritativeSourceCalculator.calculateAuthSourcesForOrgUnitTree(orgUnitId);

    long st = System.currentTimeMillis();
    for (int i = 0; i < 100; i++) {
        authoritativeSourceCalculator.calculateAuthSourcesForOrgUnitTree(orgUnitId);
    }/* w w w .j a v a  2  s .  c om*/
    long end = System.currentTimeMillis();

    System.out.println("DUR " + (end - st));
    Map<Long, Map<String, Map<Long, AuthoritativeSource>>> rulesByOrgId = authoritativeSourceCalculator
            .calculateAuthSourcesForOrgUnitTree(orgUnitId);

    System.out.println("--CIO---");
    AuthoritativeSourceCalculator.prettyPrint(rulesByOrgId.get(CIO_OFFICE));

    System.out.println("--RISK---");
    AuthoritativeSourceCalculator.prettyPrint(rulesByOrgId.get(RISK));

    System.out.println("--MARKETRISK---");
    AuthoritativeSourceCalculator.prettyPrint(rulesByOrgId.get(MARKET_RISK));

    System.out.println("--OPS---");
    AuthoritativeSourceCalculator.prettyPrint(rulesByOrgId.get(OPERATIONS_IT));

    System.out.println("--CREDIT RISK---");
    AuthoritativeSourceCalculator.prettyPrint(rulesByOrgId.get(CREDIT_RISK));

}

From source file:fr.mycellar.tools.MyCellarPasswordGenerator.java

public static void main(String... args) {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
            ApplicationConfiguration.class);
    StringPasswordEncryptor encryptor = new StringPasswordEncryptor();
    encryptor.setStringDigester(context.getBean(StringDigester.class));
    String encryptedPassword = encryptor.encryptPassword("test");
    System.out.println(encryptedPassword + " size: " + encryptedPassword.length());
}

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  . ja  v  a2  s  . c o m
    }

    applicationContext.close();
}

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

public static void main(String[] args) throws IOException {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);

    generateHierarchy(dsl);/*ww w. j  a  v  a 2  s .c  o  m*/
}