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:com.enitalk.configs.VelocityConfig.java

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

    long start = System.currentTimeMillis();
    Template t = engine.getTemplate("booking.vm");

    VelocityContext context = new VelocityContext();
    context.put("scheduledDate", new DateTime().toString());
    context.put("link", "http://localhost:8080");

    StringWriter writer = new StringWriter(24 * 1024);
    t.merge(context, writer);//  w  w w.  ja  v a2s  .  c om

    FileUtils.write(new File("/home/krash/Desktop/1.html"), writer.toString(), "UTF-8");
    logger.info("Took {}", System.currentTimeMillis() - start);
    //        String templateText = FileUtils.readFileToString(new File("./templates/booking.vm"), "UTF-8");
    //        logger.info("Templated text {}", templateText);

}

From source file:com.oreilly.springdata.rest.client.OrderClient.java

public static void main(String[] args) {

    // Bootstrap RestOperations instance using Spring
    ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(ClientConfiguration.class);
    context.registerShutdownHook();/*from   ww  w.  ja  va2 s .com*/
    RestOperations operations = context.getBean(RestOperations.class);

    // Access root resource
    ResourceSupport root = operations.getForEntity(ClientConfiguration.BASE_URL, Resource.class).getBody();
    Link orderLink = root.getLink(ClientConfiguration.ORDERS_REL);

    // Follow link to access orders
    Orders orders = operations.getForObject(orderLink.getHref(), Orders.class);

    for (Order order : orders) {

        // Follow link to access customer of the order
        Link link = order.getLink(ClientConfiguration.ORDER_CUSTOMER_REL);
        Customer customer = operations.getForObject(link.getHref(), CustomerClient.Customer.class);
        com.oreilly.springdata.rest.core.Customer domainObject = customer.getContent();
        System.out.println(
                "Order for customer: " + domainObject.getFirstname() + " " + domainObject.getLastname());
    }
}

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

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

    generateRegions(dsl);/*from  w  ww .j  a  va  2 s  .  c o m*/
}

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

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

    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);

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

    List<String> animals = IOUtilities
            .readLines(AppGenerator.class.getClassLoader().getResourceAsStream("animals.txt"));
    OrganisationalUnit[] organisationalUnits = ouDao.findAll().toArray(new OrganisationalUnit[0]);

    List<AppRegistrationRequest> registrationRequests = new ArrayList<>();

    for (int i = 0; i < 5000; i++) {
        String animal = randomPick(animals.toArray(new String[0])) + " - " + i;

        OrganisationalUnit organisationalUnit = randomPick(organisationalUnits);

        LifecyclePhase phase = rnd.nextInt(10) > 7 ? randomPick(LifecyclePhase.values())
                : LifecyclePhase.PRODUCTION;

        AppRegistrationRequest app = ImmutableAppRegistrationRequest.builder().name(animal)
                .assetCode("wltz-0" + i).description("All about " + animal)
                .kind(randomPick(ApplicationKind.values())).lifecyclePhase(phase)
                .overallRating(randomPick(RagRating.R, RagRating.A, RagRating.A, RagRating.G, RagRating.G))
                .organisationalUnitId(organisationalUnit.id().get()).build();

        registrationRequests.add(app);//from   w  w w .  j a  v  a2s .  c om
    }

    dsl.deleteFrom(AUTHORITATIVE_SOURCE).execute();
    dsl.deleteFrom(APPLICATION).execute();

    registrationRequests.forEach(applicationDao::registerApp);

}

From source file:com.hellblazer.jackal.configuration.basic.LocalGossipConfiguration.java

public static void main(String[] argv) {
    new AnnotationConfigApplicationContext(LocalGossipConfiguration.class);
}

From source file:org.smartfrog.services.anubis.partition.test.controller.gui.PartitionManagerUiConfiguration.java

public static void main(String[] argv) throws InterruptedException {
    new AnnotationConfigApplicationContext(PartitionManagerUiConfiguration.class);
    while (true) {
        Thread.sleep(50000);/*from w w w . j a  v a 2  s  .  c om*/
    }
}

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

public static void main(String[] args) {

    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);

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

    List<String> developers = getEmployeeIdsByTitle(dsl, "%developer%");
    List<String> managers = getEmployeeIdsByTitle(dsl, "%manager%");
    List<String> analysts = getEmployeeIdsByTitle(dsl, "%analyst%");
    List<String> administrators = getEmployeeIdsByTitle(dsl, "%administrator%");
    List<String> qa = getEmployeeIdsByTitle(dsl, "%qa%");
    List<String> directors = getEmployeeIdsByTitle(dsl, "%director%");
    ;/*from  w w  w.j av a 2s.  co m*/

    List<Long> orgUnitIds = dsl.select(ORGANISATIONAL_UNIT.ID).from(ORGANISATIONAL_UNIT)
            .fetch(ORGANISATIONAL_UNIT.ID);

    List<Long> inHouseApps = getAppIdsByKind(dsl, ApplicationKind.IN_HOUSE);
    List<Long> hostedApps = getAppIdsByKind(dsl, ApplicationKind.INTERNALLY_HOSTED);
    List<Long> externalApps = getAppIdsByKind(dsl, ApplicationKind.EXTERNALLY_HOSTED);
    List<Long> eucApps = getAppIdsByKind(dsl, ApplicationKind.EUC);

    List<InvolvementRecord> devInvolvements = inHouseApps.stream().map(id -> toAppRef(id))
            .flatMap(appRef -> mkInvolvments(appRef, developers, InvolvementKind.DEVELOPER, 7))
            .collect(Collectors.toList());

    List<InvolvementRecord> qaInvolvements = concat(inHouseApps, hostedApps).stream().map(id -> toAppRef(id))
            .flatMap(appRef -> mkInvolvments(appRef, qa, InvolvementKind.QA, 3)).collect(Collectors.toList());

    List<InvolvementRecord> projectManagerInvolvements = concat(inHouseApps, externalApps, hostedApps, eucApps)
            .stream().map(id -> toAppRef(id))
            .flatMap(appRef -> mkInvolvments(appRef, managers, InvolvementKind.PROJECT_MANAGER, 1))
            .collect(Collectors.toList());

    List<InvolvementRecord> supportManagerInvolvments = concat(inHouseApps, externalApps, hostedApps).stream()
            .map(id -> toAppRef(id))
            .flatMap(appRef -> mkInvolvments(appRef, managers, InvolvementKind.SUPPORT_MANAGER, 1))
            .collect(Collectors.toList());

    List<InvolvementRecord> analystInvolvments = concat(inHouseApps, externalApps, hostedApps).stream()
            .map(id -> toAppRef(id))
            .flatMap(appRef -> mkInvolvments(appRef, analysts, InvolvementKind.BUSINESS_ANALYST, 3))
            .collect(Collectors.toList());

    List<InvolvementRecord> ouArchitects = orgUnitIds.stream()
            .map(id -> new InvolvementRecord(EntityKind.ORG_UNIT.name(), id,
                    InvolvementKind.IT_ARCHITECT.name(), randomPick(directors), "RANDOM_GENERATOR"))
            .collect(Collectors.toList());

    List<InvolvementRecord> ouSponsors = orgUnitIds.stream()
            .map(id -> new InvolvementRecord(EntityKind.ORG_UNIT.name(), id,
                    InvolvementKind.BUSINESS_SPONSOR.name(), randomPick(directors), "RANDOM_GENERATOR"))
            .collect(Collectors.toList());

    dsl.delete(INVOLVEMENT).execute();

    dsl.batchInsert(devInvolvements).execute();
    dsl.batchInsert(qaInvolvements).execute();
    dsl.batchInsert(supportManagerInvolvments).execute();
    dsl.batchInsert(projectManagerInvolvements).execute();
    dsl.batchInsert(analystInvolvments).execute();
    dsl.batchInsert(ouArchitects).execute();
    dsl.batchInsert(ouSponsors).execute();

    System.out.println("Done");

}

From source file:com.hellblazer.jackal.configuration.basic.LocalMulticastConfiguration.java

public static void main(String[] argv) {
    new AnnotationConfigApplicationContext(LocalMulticastConfiguration.class);
}

From source file:stormy.pythian.sandbox.SandBox.java

public static void main(String[] args) {
    ApplicationContext context = new AnnotationConfigApplicationContext(CoreConfiguration.class);
    ComponentDescriptionFactory componentDescriptionFactory = context
            .getBean(ComponentDescriptionFactory.class);
    PythianStateDescriptionFactory stateDescriptionFactory = context
            .getBean(PythianStateDescriptionFactory.class);

    PythianStateDescription inMemoryDescription = stateDescriptionFactory
            .createDescription(InMemoryPythianState.class);
    ComponentDescription randomWordSource = componentDescriptionFactory
            .createDescription(RandomWordSource.class);
    ComponentConfiguration randomWordSourceConfiguration = new ComponentConfiguration(randomAlphabetic(6),
            randomWordSource);/*from  w w  w  .  j a  va2s.co m*/
    randomWordSourceConfiguration.add(new OutputStreamConfiguration(randomWordSource.getOutputStreams().get(0),
            createMappings(RandomWordSource.WORD_FEATURE, "random word")));

    ComponentDescription wordCount = componentDescriptionFactory.createDescription(WordCount.class);
    ComponentConfiguration wordCountConfiguration = new ComponentConfiguration(randomAlphabetic(6), wordCount);
    wordCountConfiguration.add(new InputStreamConfiguration(wordCount.getInputStreams().get(0),
            createMappings(WordCount.WORD_FEATURE, "random word")));
    wordCountConfiguration.add(new OutputStreamConfiguration(wordCount.getOutputStreams().get(0),
            createMappings(WordCount.COUNT_FEATURE, "word count")));
    wordCountConfiguration.add(stateConfiguration(inMemoryDescription).name("count state")
            .with("Transaction mode", NONE).with("Name", "Word count").build());

    ComponentDescription consoleOutput = componentDescriptionFactory.createDescription(ConsoleOutput.class);
    ComponentConfiguration consoleOutputConfiguration = new ComponentConfiguration(randomAlphabetic(6),
            consoleOutput);
    consoleOutputConfiguration.add(new InputStreamConfiguration(consoleOutput.getInputStreams().get(0),
            Arrays.asList("random word", "word count")));

    LocalCluster cluster = new LocalCluster();

    PythianToplogyConfiguration topologyConfiguration = new PythianToplogyConfiguration();
    topologyConfiguration.add(randomWordSourceConfiguration);
    topologyConfiguration.add(wordCountConfiguration);
    topologyConfiguration.add(consoleOutputConfiguration);

    topologyConfiguration.add(new ConnectionConfiguration(randomWordSourceConfiguration.getId(), "out",
            wordCountConfiguration.getId(), "in"));
    topologyConfiguration.add(new ConnectionConfiguration(wordCountConfiguration.getId(), "out",
            consoleOutputConfiguration.getId(), "in"));

    try {
        PythianTopology pythianTopology = new PythianTopology();
        pythianTopology.build(topologyConfiguration);

        cluster.submitTopology(SandBox.class.getSimpleName(), pythianTopology.getTridentConfig(),
                pythianTopology.getStormTopology());

        Utils.sleep(120000);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        cluster.shutdown();
    }

}

From source file:com.github.pjungermann.config.Application.java

public static void main(final String[] arguments) throws ConfigValidationException {
    LOGGER.info("start config validation");

    final ApplicationCLI cli;
    try {/*  ww  w  . j av  a 2s.  c om*/
        cli = new ApplicationCLI(arguments);

    } catch (MissingArgumentException | MissingOptionException | UnrecognizedOptionException e) {
        ApplicationCLI.usage();
        return;

    } catch (ParseException e) {
        LOGGER.error("arguments parsing failed", e);
        ApplicationCLI.usage();
        return;
    }

    final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
            Application.class);

    final ConfigValidator validator = context.getBean(ConfigValidator.class);
    validator.validate(cli.configs, cli.specs, cli.recursive, cli.profile, cli.strict);

    LOGGER.info("config validation finished");
}