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:com.apress.prospringintegration.social.feed.FeedInboundApp.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    ApplicationContext context = new ClassPathXmlApplicationContext("/spring/feed/feed-inbound.xml");

    PollableChannel feedChannel = context.getBean("feedChannel", PollableChannel.class);

    for (int i = 0; i < 10; i++) {
        Message<SyndEntry> message = (Message<SyndEntry>) feedChannel.receive(1000);
        if (message != null) {
            SyndEntry entry = message.getPayload();
            System.out.println(entry.getPublishedDate() + " - " + entry.getTitle());
        } else {/*w  ww  . j  a va 2 s.  c  o m*/
            break;
        }
    }
}

From source file:com.lohika.alp.reporter.client.ReporterClient.java

public static void main(String[] args) {

    ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");

    ReporterClient client = applicationContext.getBean("reporterClient", ReporterClient.class);

    client.addSuite();// ww w .j av a 2s. co  m
}

From source file:com.apress.prospringintegration.jdbc.JdbcOutbound.java

public static void main(String[] args) throws Exception {
    ApplicationContext context = new ClassPathXmlApplicationContext("/spring/jdbc/jdbc-outbound-context.xml");

    MessageChannel input = context.getBean("input", MessageChannel.class);

    Map<String, Object> rowMessage = new HashMap<String, Object>();

    rowMessage.put("id", 3);
    rowMessage.put("firstname", "Mr");
    rowMessage.put("lastname", "Bill");
    rowMessage.put("status", 0);

    Message<Map<String, Object>> message = MessageBuilder.withPayload(rowMessage).build();
    input.send(message);/*from ww  w. ja va  2s .c o  m*/

}

From source file:com.tvd.common.gateway.HelloWorldExample.java

public static void main(String args[]) {
    String cfg = "gateway/context.xml";
    @SuppressWarnings("resource")
    ApplicationContext context = new ClassPathXmlApplicationContext(cfg);
    HelloService helloService = (HelloService) context.getBean("helloGateway", HelloService.class);
    System.out.println(helloService.sayHello("World"));
}

From source file:helloworld.HelloWorldApp.java

public static void main(String[] args) {
    ApplicationContext context = new ClassPathXmlApplicationContext("spring-integration-helloword-context.xml");
    MessageChannel inputChannel = context.getBean("inputChannel", MessageChannel.class);
    PollableChannel outputChannel = context.getBean("outputChannel", PollableChannel.class);
    inputChannel.send(new GenericMessage<String>("World"));
    System.out.println("==> HelloWorldDemo: " + outputChannel.receive(0).getPayload());
}

From source file:com.gopivotal.training.VerifyClient.java

/**
 * @param args/*from  www.  j  a va  2 s . com*/
 */
public static void main(String[] args) {
    ApplicationContext context = new ClassPathXmlApplicationContext("META-INF/spring/gemfire/cache-config.xml");
    ClientCache cache = context.getBean("clientCache", ClientCache.class);
    if (cache != null) {
        new VerifyClient(cache).testClient();
    } else {
        System.out.println("Failed to initialize Client Cache");
    }
}

From source file:siia.monitoring.controlbus.ControlBusDemo.java

public static void main(String[] args) {
    ApplicationContext context = new ClassPathXmlApplicationContext("context.xml", ControlBusDemo.class);
    NumberHolder numberHolder = context.getBean("numberHolder", NumberHolder.class);
    MessageChannel controlChannel = context.getBean("controlChannel", MessageChannel.class);
    System.out.println("number before increment: " + numberHolder.getNumber());
    Message<String> message = MessageBuilder.withPayload("@numberHolder.increment()").build();
    controlChannel.send(message);// w w w .  j a  va2 s. c om
    System.out.println("number after increment:  " + numberHolder.getNumber());
    FilePoller filePoller = context.getBean("filePoller", FilePoller.class);
    System.out.println("file poller isRunning before start: " + filePoller.isRunning());
    controlChannel.send(MessageBuilder.withPayload("@filePoller.start()").build());
    System.out.println("file poller isRunning after start:  " + filePoller.isRunning());
    controlChannel.send(MessageBuilder.withPayload("@filePoller.stop()").build());
    System.out.println("file poller isRunning after stop:   " + filePoller.isRunning());
    ThreadPoolTaskExecutor executor = context.getBean("myExecutor", ThreadPoolTaskExecutor.class);
    System.out.println("max pool size before update: " + executor.getMaxPoolSize());
    controlChannel.send(MessageBuilder.withPayload("@myExecutor.setMaxPoolSize(25)").build());
    System.out.println("max pool size after update:  " + executor.getMaxPoolSize());
}

From source file:com.shopzilla.api.driver.ProductServiceDriver.java

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

    ApplicationContext applicationContext = new ClassPathXmlApplicationContext(
            "classpath:applicationContext.xml");
    ProductService service = applicationContext.getBean("productService", ProductService.class);

    //service.xmlInputStreamToJava();
}

From source file:com.shopzilla.api.driver.ProductClientDriver.java

public static void main(String[] args) {
    ApplicationContext applicationContext = new ClassPathXmlApplicationContext(
            "classpath:applicationContext.xml");
    ProductClient client = applicationContext.getBean("productClient", ProductClient.class);
    credentialFactory = applicationContext.getBean("credentialFactory", CredentialFactory.class);
    apiKey = credentialFactory.getPublisherApiKey();
    publisherId = credentialFactory.getPublisherId();
    client.doProductSearch(apiKey, publisherId, keyword, 10);
}

From source file:com.smith.http.webservice.WebSocketServer.java

public static void main(String[] args) {
    int port;//from  w  w  w.ja  v a 2 s . c o  m
    if (args.length > 0) {
        port = Integer.parseInt(args[0]);
    } else {
        port = 8080;
    }
    ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
    TNUtil.dao = context.getBean("dao", DaoImpl.class);
    new WebSocketServer(port).run();
}