Example usage for org.springframework.beans.factory BeanFactory getBean

List of usage examples for org.springframework.beans.factory BeanFactory getBean

Introduction

In this page you can find the example usage for org.springframework.beans.factory BeanFactory getBean.

Prototype

<T> T getBean(Class<T> requiredType) throws BeansException;

Source Link

Document

Return the bean instance that uniquely matches the given object type, if any.

Usage

From source file:occi.libvirt.StartClass.java

public static void main(String[] args) {
    ApplicationContext context = new ClassPathXmlApplicationContext("resources/conf/beans.xml");
    BeanFactory factory = context;
    Injection test = (Injection) factory.getBean("Injection");
    try {/*from   w w  w .  java2s  . c  o  m*/
        occiApi.main(null);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:net.ab0oo.aprs.big.BIG.java

public static void main(String[] args) throws Exception {
    BeanFactory factory = new XmlBeanFactory(new FileSystemResource("big.xml"));
    Server server = (Server) factory.getBean("WebServer");
    server.start();/* w w  w  .  j a va  2s  .  c om*/
}

From source file:com.bizintelapps.proaccounting.service.impl.UsersServiceImpl.java

public static void main(String[] args) {
    ApplicationContext context = new ClassPathXmlApplicationContext(
            new String[] { "classpath:applicationContext-dao.xml", "classpath:applicationContext-service.xml",
                    "classpath:applicationContext-service-transactions.xml",
                    "classpath:applicationContext-schedule.xml", });

    // an ApplicationContext is also a BeanFactory (via inheritance)
    BeanFactory factory = (BeanFactory) context;
    UsersService uas = (UsersService) factory.getBean("usersServiceImpl");
    Users u = new Users(10, "alskdj", "asldjf", true);
    uas.saveUser(u);//from  w w  w  .ja va  2 s  .  com
}

From source file:net.ab0oo.aprs.clients.JmsBroker.java

public static void main(String[] args) throws Exception {
    BeanFactory factory = new XmlBeanFactory(new FileSystemResource("web/WEB-INF/classes/broker.xml"));
    factory.getBean("broker");
    System.out.println("JMS Broker starting up");
    while (true) {
        try {//from   w w w . j  a v a 2  s .co  m
            Thread.sleep(10000);
        } catch (InterruptedException iex) {

        }
    }
}

From source file:com.bizintelapps.proaccounting.ajax.UsersAjaxService.java

public static void main(String[] args) {
    ApplicationContext context = new ClassPathXmlApplicationContext(
            new String[] { "classpath:applicationContext-dao.xml", "classpath:applicationContext-service.xml",
                    "classpath:applicationContext-service-transactions.xml",
                    "classpath:applicationContext-schedule.xml", "classpath:applicationContext-ajax.xml" });

    // an ApplicationContext is also a BeanFactory (via inheritance)
    BeanFactory factory = (BeanFactory) context;
    UsersAjaxService uas = (UsersAjaxService) factory.getBean("usersAjaxService");
    //uas.saveUser("imran");
}

From source file:org.voltdb.example.springjdbc.SpringJDBCTemplateTest.java

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

    GenericApplicationContext ctx = new GenericXmlApplicationContext("/applicationContext.xml");
    BeanFactory factory = ctx;
    ContestantDao contestantDao = (ContestantDao) factory.getBean("contestantDao");

    List<ContestantData> list = contestantDao.findContestant("0");
    if (list == null || list.size() == 0) {
        contestantDao.insertContestant("foo", "bar", "0");
    }/*  ww w.  j  av  a 2s .c  o m*/
    list = contestantDao.findContestant("0");
    if (list.size() == 1) {
        System.out.println("Insert Success");
        ContestantData d = list.get(0);
        if (!d.getCode().equals("0") || !d.getFirstName().equals("foo") || !d.getLastName().equals("bar")) {
            System.out.println("Insert failed");
        }
    }
    contestantDao.updateContestant("foo2", "bar2", "0");
    list = contestantDao.findContestant("0");
    if (list.size() == 1) {
        System.out.println("Update Success");
        ContestantData d = list.get(0);
        if (!d.getCode().equals("0") || !d.getFirstName().equals("foo2") || !d.getLastName().equals("bar2")) {
            System.out.println("Update faild");
        }
    }

    contestantDao.insertContestant(null, null, "1");
    list = contestantDao.getAllContestants();
    if (list.size() == 2) {
        System.out.println("Get All Successful.");
    }

    contestantDao.deleteContestant("1");
    System.out.println("Delete was Successful.");
    contestantDao.insertContestant(null, null, "1");
    contestantDao.deleteAllContestants();
    System.out.println("Delete All was Successful.");
}

From source file:com.milkdairy.admin.MilkDairyManagement.java

public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            Resource resource = new ClassPathResource("applicationContext.xml");
            BeanFactory factory = new XmlBeanFactory(resource);

            JPanel milkDairyManagementJPanel = (MilkDairyManagementJPanel) factory
                    .getBean("milkDairyManagementJPanel");

            UIManager.put("swing.boldmetal", Boolean.FALSE);

            new LoginJFrame(milkDairyManagementJPanel, (LoggingService) factory.getBean("loggingService"))
                    .setVisible(true);//from  w  w  w . j a  v a  2  s.  co  m

        }

    });
}

From source file:it.dontesta.spring.example.main.MinimalSpringApp.java

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

    GenericApplicationContext ctx = SpringContext.getContext();
    BeanFactory factory = ctx;
    IHorseDAO horseDAO = (IHorseDAO) factory.getBean("horseDAOImpl");

    log.info("Create a Horse table...");
    horseDAO.createTable();/*ww  w . j  a  v  a 2s. com*/

    log.info("Adding Horse data object...");
    horseDAO.createHorse("Shirus", "9", "Quarab", "Grigio", RandomStringUtils.random(15, false, true));
    horseDAO.createHorse("Eclisse", "13", "Appalousa", "Pezzato con coperta",
            RandomStringUtils.random(15, false, true));
    horseDAO.createHorse("Morgana", "6", "Maremmana", "Baia", RandomStringUtils.random(15, false, true));
    horseDAO.createHorse("Macchia", "12", "Appalousa", "Morello", RandomStringUtils.random(15, false, true));

    log.info("Retrieving data..");
    for (Horse currentHorse : horseDAO.selectAll()) {
        log.info("From DB: " + currentHorse.toString());
    }

    log.info("Deleting record macchia and viewing...");
    horseDAO.deleteHorse("macchia");
    for (Horse currentHorse : horseDAO.selectAll()) {
        log.info("From DB: " + currentHorse.toString());
    }

    log.info("Adding a new record and viewing...");
    horseDAO.createHorse("Furia", "10", "Appalousa", "Morello", RandomStringUtils.random(15, false, true));
    for (Horse currentHorse : horseDAO.selectAll()) {
        log.info("From DB: " + currentHorse.toString());
    }

    log.info("Deleting everything and viewing...");
    horseDAO.deleteAll();
    for (Horse currentHorse : horseDAO.selectAll()) {
        log.info("From DB: " + currentHorse.toString());
    }

    log.info("Drop a Horse table...");
    horseDAO.dropTable();

}

From source file:org.restlet.example.book.restlet.ch03.sec3.server.MailServerSpring.java

public static void main(String[] args) throws Exception {
    // Load the Spring container
    ClassPathResource resource = new ClassPathResource(
            "org/restlet/example/book/restlet/ch04/sec3/server/component-spring.xml");
    BeanFactory factory = new XmlBeanFactory(resource);

    // Start the Restlet component
    Component component = (Component) factory.getBean("component");
    component.start();/*  w  ww .  j  a v  a2  s .  com*/
}

From source file:net.ab0oo.aprs.SpringServer.java

public static void main(String[] args) throws Exception {
    BeanFactory factory = null;
    if (args.length > 0) {
        factory = new XmlBeanFactory(new FileSystemResource(args[0]));
        factory.getBean("tcpClient");

    } else {//from   www.j  a va2  s.  c o m
        factory = new XmlBeanFactory(new FileSystemResource("web/WEB-INF/classes/wedjat.xml"));
        factory.getBean("tcpClient");
    }
}