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:de.linsin.sample.spring.integration.Bootstrap.java

private static void toOutputChannel(ApplicationContext argCtx) {
    MessageChannel input = (MessageChannel) argCtx.getBean("input");
    PollableChannel output = (PollableChannel) argCtx.getBean("output");
    input.send(new StringMessage("Spring Integration rocks"));
    Message<?> reply = output.receive();
    System.out.println("received: " + reply);
}

From source file:com.home.ln_spring.ch5.lifecycle.SimpleBean.java

private static SimpleBean getBean(String beanName, ApplicationContext ctx) {
    try {//from   w ww .  j av a2 s  .  c o  m
        SimpleBean sb = (SimpleBean) ctx.getBean(beanName);
        System.out.println(sb);
        return sb;
    } catch (BeanCreationException ex) {
        System.out.println("An error occured in bean configuration1: " + ex.getMessage());
        return null;
    }
}

From source file:gov.nih.nci.cadsrapi.dao.orm.TestORMDAO.java

public static void main() {

    ApplicationContext context = new ClassPathXmlApplicationContext("application-config.xml");
    CartORMDAOImpl cart = (CartORMDAOImpl) context.getBean("ORMDAO");

}

From source file:com.joshlong.activiti.coordinator.registration1.distribution.producer.RegistrationProducerMain.java

/**
 * generates new processes in response to a read-line
 * @param ctx/*from  ww w .  j a  va2  s . c  om*/
 * @throws Throwable
 */
static void doReadLine(ApplicationContext ctx) throws Throwable {
    ProcessEngine processEngine = ctx.getBean(ProcessEngine.class);

    String line;
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

    while (true) {
        System.out.println("which customer would you like to start a fulfillment "
                + "process for? Enter it, then hit <Enter>:");
        line = reader.readLine();
        Integer customerId = Integer.parseInt(StringUtils.defaultString(line).trim());
        Map<String, Object> vars = Collections.singletonMap("customerId", (Object) customerId);
        processEngine.getRuntimeService().startProcessInstanceByKey("customer-fullfillment-process", vars);
    }
}

From source file:com.mvdb.etl.actions.InitDB.java

private static void createOrder(ApplicationContext context) {
    final OrderDAO orderDAO = (OrderDAO) context.getBean("orderDAO");

    String[] commands = { "DROP SEQUENCE IF EXISTS " + SequenceNames.ORDER_SEQUENCE_NAME + ";",
            "CREATE SEQUENCE com_mvdb_etl_dao_OrderDAO START 1;", "COMMIT;", "DROP TABLE IF EXISTS orders;",
            "CREATE TABLE  orders (" + " ORDER_ID bigint  NOT NULL, " + " NOTE varchar(200) NOT NULL,"
                    + " SALE_CODE int NOT NULL," + " CREATE_TIME timestamp NOT NULL,"
                    + " UPDATE_TIME timestamp NOT NULL, " + "constraint order_pk PRIMARY KEY (ORDER_ID)"
                    + " ); ",
            "COMMIT;" };

    orderDAO.executeSQl(commands);// www. j  a va  2s .  co m

}

From source file:com.home.ln_spring.ch5.lifecycle.SimpleBeanWithInterface.java

private static SimpleBeanWithInterface getBean(String beanName, ApplicationContext ctx) {
    try {/*from  w w w .  j  a v a 2s  .co  m*/
        SimpleBeanWithInterface sb = (SimpleBeanWithInterface) ctx.getBean(beanName);
        System.out.println(sb);
        return sb;
    } catch (BeanCreationException ex) {
        System.out.println("An error occured in bean configuration1: " + ex.getMessage());
        return null;
    }
}

From source file:com.joshlong.activiti.coordinator.registration1.distribution.producer.RegistrationProducerMain.java

/**
 * continues generating new processes until it reaches a certain count
 *//*from   w  ww.ja v  a  2 s . c o m*/
static void doContinuousIterationUpUntil(ApplicationContext ctx, int counter) throws Throwable {
    ProcessEngine processEngine = ctx.getBean(ProcessEngine.class);
    for (int customerId = 0; customerId < counter; customerId++) {
        Map<String, Object> vars = Collections.singletonMap("customerId", (Object) customerId);
        processEngine.getRuntimeService().startProcessInstanceByKey("customer-fullfillment-process", vars);
    }
    while (true)
        Thread.sleep(10000);
}

From source file:us.sodiumlabs.survey.core.App.java

private static void loadSurveys(ApplicationContext context) {
    ISurveyDAO dao = (ISurveyDAO) context.getBean("defaultSurveyDAO");

    dao.save(loadIceCreamSurvey(context));
    dao.save(loadSuperheroSurvey(context));
}

From source file:com.borgrodrick.creditinfo.FileCopyDemoCommon.java

public static void displayDirectories(ApplicationContext context) {
    File inDir = (File) new DirectFieldAccessor(context.getBean(FileReadingMessageSource.class))
            .getPropertyValue("directory");
    LiteralExpression expression = (LiteralExpression) new DirectFieldAccessor(
            context.getBean(FileWritingMessageHandler.class))
                    .getPropertyValue("destinationDirectoryExpression");
    File outDir = new File(expression.getValue());

    System.out.println("Input directory is: " + inDir.getAbsolutePath());
    System.out.println("Output directory is: " + outDir.getAbsolutePath());
    System.out.println("===================================================");
}

From source file:us.sodiumlabs.survey.core.App.java

private static void loadSurveysIfNotLoaded(ApplicationContext context) {
    ISurveyDAO dao = (ISurveyDAO) context.getBean("defaultSurveyDAO");

    if (dao.getAllSurveys().isEmpty()) {
        loadSurveys(context);/*from w w  w  .  j  a v  a2s.  com*/
    }
}