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

Object getBean(String name) throws BeansException;

Source Link

Document

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

Usage

From source file:net.tirasa.blog.ilgrosso.dynamicspringtransactional.App.java

public static void main(final String[] args) {
    ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");

    TransactionalClass txClass = ctx.getBean(TransactionalClass.class);

    AuthContextUtils.setDomain("domain1");
    txClass.transactionalMethod();/*from  ww w.  ja  v  a2 s  .co  m*/

    AuthContextUtils.setDomain("domain2");
    txClass.transactionalMethod();
}

From source file:prospring3.ch5.beanpostprocessor.DeassociateMain.java

public static void main(String[] args) {
    ApplicationContext ctx = new AnnotationConfigApplicationContext(Ch5Config.class);
    final FacebookService facebookService = ctx.getBean(FacebookService.class);
    facebookService.deassociate();//ww w.j  av  a 2s  .  c  o m
    System.out.println("Finish");
}

From source file:com.apress.prospringintegration.ip.TcpGatewaySend.java

public static void main(String[] args) {
    ApplicationContext context = new ClassPathXmlApplicationContext("spring/ip/tcp-gateway.xml");
    TcpGateway gateway = (TcpGateway) context.getBean("tcpGateway");
    String reply = gateway.sendTcp("TCP Gateway Message");
    System.out.println("Reply: " + reply);
}

From source file:com.us.test.PageTest.java

public static void main(String[] args) {

    ApplicationContext app = new ClassPathXmlApplicationContext("classpath:/applicationContext.xml");

    IDao dao = app.getBean(IDao.class);

    DetachedCriteria criteria = dao.init(User.class);
    criteria.addOrder(Order.asc("uuid"));
    criteria.addOrder(Order.asc("name"));
    criteria.add(Restrictions.gt("uuid", 0l));

    dao.findPage(criteria, 1, 20);/*from  ww  w. j a v  a  2 s .c o  m*/

}

From source file:org.shareok.data.msofficedata.Main.java

public static void main(String[] args) throws Exception {
    ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
    FileRouter router = (FileRouter) context.getBean("fileRouter");
    ExcelHandler excelHandler = (ExcelHandler) context.getBean("excelHandler");
    //PlosOneExcelData plosOneData = (PlosOneExcelData) context.getBean("plosOneExcelData");
    String path = FileUtil.getFilePathFromResources("plos_articles.xlsx");
    excelHandler.setFileName(path);//from  ww w  .  j  av  a2  s . c  o  m
    excelHandler.readData();

    //String obj.getFileExtension();
}

From source file:com.apress.prospringintegration.concurrency.taskexecutorexample.TaskExecutorExampleApp.java

public static void main(String[] args) {
    ApplicationContext ctx = new AnnotationConfigApplicationContext(TaskExecutorExampleConfiguration.class);
    TaskExecutorExample demo = ctx.getBean(TaskExecutorExample.class);
    demo.submitJobs();/*from   w w  w . ja v  a 2  s .c om*/
}

From source file:org.blanco.test.spring.xmltest.Main.java

public static void main(String args[]) throws XmlMappingException, IOException {
    ApplicationContext ctx = new ClassPathXmlApplicationContext("/spring-config.xml");
    Marshaller mar = (Marshaller) ctx.getBean("marshaller");
    Person alex = (Person) ctx.getBean("alex");
    Result result = new StreamResult(System.out);
    mar.marshal(alex, result);/*from w  w  w .j  a  va2s  .  c  o  m*/

    System.exit(0);
}

From source file:com.facio.Main.java

public static void main(String[] args) {
    LOG.info("start main and loading application context...");
    int i = 0;/*from  w  w  w.jav a2  s  .  c om*/
    String[] names = { "Vai Planeta", "Fabiano", "Lucas" };

    ApplicationContext ctx = new AnnotationConfigApplicationContext(MainConfig.class);

    HeavyService bean = ctx.getBean(HeavyService.class);
    IDummyComponent<String, String> dummy = ctx.getBean(IDummyComponent.class);

    //        for (i = 0; i < 3; i++) {
    //            LOG.info("calling hello... for the [" + i + "] time");
    //            String hello = bean.hello(names[0]);
    //            LOG.debug("Say.:" + hello);
    //            LOG.info("hello called.");
    //        }

    dummy.getValue("mykey", "myname");
}

From source file:br.com.gumga.academia.aplicacao.MainService3.java

public static void main(String[] args) {
    ApplicationContext ctx = new AnnotationConfigApplicationContext(Aplicacao.class);
    MainService3 ms = ctx.getBean(MainService3.class);
    ms.run();/*from w  w  w  .  ja  v  a 2  s.c o m*/
}

From source file:com.home.ln_spring.ch5.event.Publisher.java

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

    Publisher p = (Publisher) context.getBean("publisher");
    p.publish("Hello World!!!");
    p.publish("The quik brown fox jumperd over the lazy dog");
}