Example usage for org.springframework.context ApplicationContext getBean

List of usage examples for org.springframework.context ApplicationContext getBean

Introduction

In this page you can find the example usage for org.springframework.context ApplicationContext getBean.

Prototype

<T> T getBean(String name, Class<T> requiredType) throws BeansException;

Source Link

Document

Return an instance, which may be shared or independent, of the specified bean.

Usage

From source file:nl.han.dare2date.service.UserNotification.java

public static void main(String args[]) {
    ApplicationContext context = new ClassPathXmlApplicationContext("userNotificationContext.xml");

    UserNotification userNotification = context.getBean("userNotification", UserNotification.class);
}

From source file:org.springone2gx_2011.integration.resequencer.ResequencerDemo.java

/**
 * @param args//from   w w w .jav a2  s. co  m
 */
public static void main(String[] args) throws Exception {
    ApplicationContext context = new ClassPathXmlApplicationContext("resequencer-config.xml",
            ResequencerDemo.class);
    MessageChannel inputChannel = context.getBean("inputChannel", MessageChannel.class);

    inputChannel.send(MessageBuilder.withPayload(5).setCorrelationId(1).setSequenceNumber(5).build());
    inputChannel.send(MessageBuilder.withPayload(2).setCorrelationId(1).setSequenceNumber(2).build());
    inputChannel.send(MessageBuilder.withPayload(1).setCorrelationId(1).setSequenceNumber(1).build());

    inputChannel.send(MessageBuilder.withPayload(2).setCorrelationId(2).setSequenceNumber(2).build());
    inputChannel.send(MessageBuilder.withPayload(1).setCorrelationId(2).setSequenceNumber(1).build());

    inputChannel.send(MessageBuilder.withPayload(4).setCorrelationId(1).setSequenceNumber(4).build());
    inputChannel.send(MessageBuilder.withPayload(3).setCorrelationId(1).setSequenceNumber(3).build());

    inputChannel.send(MessageBuilder.withPayload(5).setCorrelationId(2).setSequenceNumber(5).build());
    inputChannel.send(MessageBuilder.withPayload(4).setCorrelationId(2).setSequenceNumber(4).build());
    inputChannel.send(MessageBuilder.withPayload(3).setCorrelationId(2).setSequenceNumber(3).build());

    System.in.read();
}

From source file:com.reversemind.hypergate.spring.HyperGateClientSpringContextLoader.java

public static void main(String... args) throws Exception {
    ApplicationContext applicationContext = new ClassPathXmlApplicationContext(
            "META-INF/hypergate-client-context.xml");

    HyperGateClientServerDiscovery client = (HyperGateClientServerDiscovery) applicationContext.getBean(
            AbstractContainerHyperGateClient.CLIENT_DISCOVERY_BUILDER_NAME,
            AbstractContainerHyperGateClient.CLASS_HYPERGATE_CLIENT_SERVER_DISCOVERY);

    client.start();// w w  w . j  a  va 2 s. co m

    Thread.sleep(40000);

    client.shutdown();

}

From source file:com.wlami.mibox.client.application.MiboxClientApp.java

/**
 * Main entry point for the MiboxClientApplication.
 * //from   w ww  .  j a v  a2  s. c o m
 * @param args
 *            no command line arguments needed.
 * @throws IOException
 *             thrown, if app properties cannot be loaded.
 */
public static void main(final String[] args) throws IOException {
    log.info("Startup mibox client.");
    Security.addProvider(new BouncyCastleProvider());
    ApplicationContext ctx = new ClassPathXmlApplicationContext("spring.xml");
    MiboxClientApp miboxClientApp = ctx.getBean("miboxClientApp", MiboxClientApp.class);
    miboxClientApp.run();
}

From source file:test.go.java

public static void main(String... args) {
    System.setProperty("curator-log-events", "true");

    IHyperGateServer server;//from   ww  w . java2s . c  om

    ApplicationContext applicationContext = new ClassPathXmlApplicationContext(
            "META-INF/hypergate-server-context.xml");
    ServerFactory.Builder builderAdvertiser = applicationContext.getBean("serverBuilder",
            ServerFactory.Builder.class);

    LOG.debug("--------------------------------------------------------");
    LOG.debug("Builder properties:");
    LOG.debug("Name:" + builderAdvertiser.getName());
    LOG.debug("Instance Name:" + builderAdvertiser.getInstanceName());
    LOG.debug("port:" + builderAdvertiser.getPort());
    LOG.debug("isAutoSelectPort:" + builderAdvertiser.isAutoSelectPort());

    LOG.debug("Type:" + builderAdvertiser.getType());

    LOG.debug("Zookeeper connection string:" + builderAdvertiser.getZookeeperHosts());
    LOG.debug("Zookeeper base path:" + builderAdvertiser.getServiceBasePath());

    server = builderAdvertiser.build();

    LOG.debug("\n\n");
    LOG.debug("--------------------------------------------------------");
    LOG.debug("After server initialization - properties");
    LOG.debug("\n");
    LOG.debug("Server properties:");
    LOG.debug("......");
    LOG.debug("Name:" + server.getName());
    LOG.debug("Instance Name:" + server.getInstanceName());
    LOG.debug("port:" + server.getPort());

    server.start();

    LOG.debug("Server started");
}

From source file:org.psidnell.omnifocus.Main.java

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

    ActiveOptionProcessor<CommandLine> processor = new ActiveOptionProcessor<>(PROG, OPTIONS);

    boolean cmdLineFailure = !processor.processOptions(null, args, STARTUP);

    ApplicationContext appContext = ApplicationContextFactory.getContext();

    Main main = appContext.getBean("main", Main.class);
    main.setProcessor(processor);//from   w  w w. j  a va2s.  c  om

    if (cmdLineFailure || "true".equals(System.getProperty(CommandLine.PRINT_HELP))) {
        main.printHelp();
        return;
    }

    if ("true".equals(System.getProperty(CommandLine.PRINT_INFO))) {
        main.printAdditionalInfo();
        return;
    }

    main.procesPreLoadOptions(args);

    if (main.exportFile != null) {
        main.data.exportData(new File(main.exportFile), (f) -> true);
        return;
    }

    main.loadData();

    main.processPostLoadOptions(args);

    main.run();

    LOGGER.debug("Exiting");
}

From source file:com.dbs.posttrade.camel.client.CamelClientRemoting.java

public static void main(final String[] args) throws Exception {
    _log.debug("Notice this client requires that the CamelServer is already running!");

    ApplicationContext context = new ClassPathXmlApplicationContext(
            "spring/camel-applicationContext-client.xml");

    GenericRepositoryInterface<ReportType, Long> genericRepositoryInterface = context
            .getBean("reportTypeRepository", GenericRepositoryInterface.class);

    ReportType a = genericRepositoryInterface.getById(1L);
    System.out.println("... the result is: " + a);

    System.exit(0);/* w  w  w  .  j a  v a  2s .com*/
}

From source file:org.thys.michels.email2sfdc.email.GmailInboundImapIdleAdapterTestApp.java

public static void main(String[] args) throws Exception {
    ApplicationContext context = new ClassPathXmlApplicationContext(
            "/META-INF/spring/integration/gmail-imap-idle-config.xml");

    final ParseEmail parseEmailMessage = new ParseEmail();

    DirectChannel inputChannel = context.getBean("inputChannel", DirectChannel.class);
    inputChannel.subscribe(new MessageHandler() {
        public void handleMessage(Message<?> message) throws MessagingException {
            //logger.info("Message: " + message);
            parseEmailMessage.printMessage(parseEmailMessage.getEmailMessage(message));

        }// w  w w .ja va  2  s .c  o  m
    });
}

From source file:org.jasig.portlet.announcements.Exporter.java

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

    String dir = args[0];//from w ww  .ja v  a2  s. c o m
    ApplicationContext context = PortletApplicationContextLocator
            .getApplicationContext(PortletApplicationContextLocator.DATABASE_CONTEXT_LOCATION);
    SessionFactory sessionFactory = context.getBean(SESSION_FACTORY_BEAN_NAME, SessionFactory.class);
    IAnnouncementService announcementService = context.getBean(ANNOUNCEMENT_SVC_BEAN_NAME,
            IAnnouncementService.class);

    Session session = sessionFactory.getCurrentSession();
    Transaction transaction = session.beginTransaction();

    JAXBContext jc = JAXBContext.newInstance(Topic.class);
    Marshaller marshaller = jc.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

    List<Topic> topics = announcementService.getAllTopics();
    for (Topic topic : topics) {
        if (topic.getSubscriptionMethod() == 4) {
            continue;
        }

        session.lock(topic, LockMode.NONE);
        JAXBElement<Topic> je2 = new JAXBElement<Topic>(new QName("topic"), Topic.class, topic);
        String output = dir + File.separator + UUID.randomUUID().toString() + ".xml";
        System.out.println("Exporting Topic " + topic.getId() + " to file " + output);
        try {
            marshaller.marshal(je2, new FileOutputStream(output));
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }
    transaction.commit();
}

From source file:org.jasig.portlet.announcements.SchemaCreator.java

public static void main(String[] args) {

    // There will be an instance of this class in the ApplicationContent
    ApplicationContext context = PortletApplicationContextLocator
            .getApplicationContext(PortletApplicationContextLocator.DATABASE_CONTEXT_LOCATION);
    final SchemaCreator schemaCreator = context.getBean("schemaCreator", SchemaCreator.class);
    System.exit(schemaCreator.create());
}