Example usage for org.springframework.context.support ClassPathXmlApplicationContext getBean

List of usage examples for org.springframework.context.support ClassPathXmlApplicationContext getBean

Introduction

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

Prototype

@Override
    public Object getBean(String name) throws BeansException 

Source Link

Usage

From source file:fr.xebia.exercice.Main.java

public static void runVersionProcedurale() {
    ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(
            "/applicationContext-versionProcedurale.xml", Main.class);
    WebControllerVersionProcedurale webController = applicationContext
            .getBean(WebControllerVersionProcedurale.class);
    double valoPortfolio = webController.valorisePortfolio(1);
    System.out.println("valoPortfolio = " + valoPortfolio);
}

From source file:com.base2.kagura.services.camel.utils.TestUtils.java

public static AbstractApplicationContext buildContext() {
    ClassPathXmlApplicationContext classPathXmlApplicationContext = new ClassPathXmlApplicationContext(
            "/META-INF/spring/test.xml");
    ServerBean serverBean = (ServerBean) classPathXmlApplicationContext.getBean("serverBean");
    serverBean.setConfigPath(getResourcePath("TestReports"));
    FileAuthentication fileAuthentication = (FileAuthentication) classPathXmlApplicationContext
            .getBean("fileAuthentication");
    fileAuthentication.setConfigPath(getResourcePath("TestReports"));
    FileReportsProvider fileReportsProvider = (FileReportsProvider) classPathXmlApplicationContext
            .getBean("fileReportsProvider");
    fileReportsProvider.setReportDirectory(getResourcePath("TestReports"));
    return classPathXmlApplicationContext;
}

From source file:com.dinstone.jrpc.example.spring.ServiceWithSpring.java

protected static void jackson(ClassPathXmlApplicationContext applicationContext) {
    HelloService service = (HelloService) applicationContext.getBean("rhsv1-1");
    if (service == null) {
        return;/*  w  w w  . ja  v  a  2s  .  co  m*/
    }

    System.out.println("jackson");
    try {
        testHot(service);
    } catch (Exception e) {
        e.printStackTrace();
    }

    try {
        testSend1k(service);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.dinstone.jrpc.example.spring.ServiceWithSpring.java

protected static void protobuff(ClassPathXmlApplicationContext applicationContext) {
    HelloService service = (HelloService) applicationContext.getBean("rhsv1");
    if (service == null) {
        return;/*from   ww w  .  j  a  va2s  .  com*/
    }

    System.out.println("protobuff");
    try {
        testHot(service);
    } catch (Exception e) {
        e.printStackTrace();
    }

    try {
        testSend1k(service);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:guru.qas.martini.annotation.StepsAnnotationProcessorTest.java

private static void process(ClassPathXmlApplicationContext context, Object... beans) {
    StepsAnnotationProcessor processor = context.getBean(StepsAnnotationProcessor.class);
    for (Object bean : beans) {
        processor.postProcessAfterInitialization(bean, bean.getClass().getName());
    }/*from   w w  w.  j a v a 2  s.  c  o  m*/
}

From source file:eu.databata.engine.util.PropagatorTableExport.java

private static JdbcTemplate initializeExport() {
    ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(
            "WEB-INF/propagator-db-beans.xml");
    JdbcTemplate jdbcTemplate = (JdbcTemplate) applicationContext.getBean("jdbcTemplate");
    System.out.println("\nDB table export utility is activated.");
    return jdbcTemplate;
}

From source file:demo.jaxrs.client.LocalTransportTest.java

public static void startSpringTest() {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] {
            "classpath:client-applicationContext.xml", "classpath:server-applicationContext.xml" });
    CustomerService proxy = (CustomerService) context.getBean("restClient");
    //        WebClient.getConfig(proxy).getRequestContext().put(LocalConduit.DIRECT_DISPATCH, "true");

    Bus bus = new SpringBusFactory(context).createBus();
    BusFactory.setDefaultBus(bus);/*  w  w  w .  j  a  v a2 s.  c o  m*/

    List<PolicyTO> policies = (List<PolicyTO>) proxy.listByType(PolicyType.PASSWORD);
    for (PolicyTO policy : policies) {
        System.out.println("Policy: " + policy.getId());
    }
}

From source file:gr.seab.r2rml.beans.MainParser.java

public static void runParcer(String[] args) {
    Calendar c0 = Calendar.getInstance();
    long t0 = c0.getTimeInMillis();

    CommandLineParser cmdParser = new PosixParser();

    Options cmdOptions = new Options();
    cmdOptions.addOption("p", "properties", true,
            "define the properties file. Example: r2rml-parser -p r2rml.properties");
    cmdOptions.addOption("h", "print help", false, "help");

    String propertiesFile = "r2rml.properties";

    try {// w w w .  j a v a2 s . c  o  m
        if (StringUtils.isNotEmpty(propertiesFile)) {
            properties.load(new FileInputStream(propertiesFile));
            log.info("Loaded properties from " + propertiesFile);
            if (args != null && args.length > 0 && args[0].equals("fixProperty")) {
                properties = fixProperty(properties);
            }
        }
    } catch (FileNotFoundException e) {
        //e.printStackTrace();
        String err = "Properties file not found (" + propertiesFile + ").";
        log.error(err);
        throw new RuntimeException(err);
        //System.exit(0);
    } catch (IOException e) {
        //e.printStackTrace();
        String err = "Error reading properties file (" + propertiesFile + ").";
        log.error(err);
        throw new RuntimeException(err);
        //System.exit(0);
    }

    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("app-context.xml");

    Database db = (Database) context.getBean("db");
    db.setProperties(properties);

    Parser parser = (Parser) context.getBean("parser");
    parser.setProperties(properties);

    MappingDocument mappingDocument = parser.parse();

    mappingDocument.getTimestamps().add(t0); //0 Started
    mappingDocument.getTimestamps().add(Calendar.getInstance().getTimeInMillis()); //1 Finished parsing. Starting generating result model.

    Generator generator = (Generator) context.getBean("generator");
    generator.setProperties(properties);
    generator.setResultModel(parser.getResultModel());

    //Actually do the output
    generator.createTriples(mappingDocument);

    context.close();
    Calendar c1 = Calendar.getInstance();
    long t1 = c1.getTimeInMillis();
    log.info("Finished in " + (t1 - t0) + " milliseconds. Done.");
    mappingDocument.getTimestamps().add(Calendar.getInstance().getTimeInMillis()); //5 Finished.
    //log.info("5 Finished.");

    //output the result
    for (int i = 0; i < mappingDocument.getTimestamps().size(); i++) {
        if (i > 0) {
            long l = (mappingDocument.getTimestamps().get(i).longValue()
                    - mappingDocument.getTimestamps().get(i - 1).longValue());
            //System.out.println(l);
            log.info(String.valueOf(l));
        }
    }
    log.info("Parse. Generate in memory. Dump to disk/database. Log. - Alltogether in "
            + String.valueOf(mappingDocument.getTimestamps().get(5).longValue()
                    - mappingDocument.getTimestamps().get(0).longValue())
            + " msec.");
    log.info("Done.");
    System.out.println("Done.");
}

From source file:com.dinstone.jrpc.example.spring.ServiceWithSpring.java

protected static void case03() {
    ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(
            "jrpc-example-case3.xml");

    HelloService rhsv1 = (HelloService) applicationContext.getBean("rhsv1");

    try {/*from  w w  w.  j a  v  a  2 s .  c o  m*/
        testHot(rhsv1);
    } catch (Exception e) {
        e.printStackTrace();
    }

    try {
        testSend1k(rhsv1);
    } catch (Exception e) {
        e.printStackTrace();
    }

    try {
        System.in.read();
    } catch (IOException e) {
    }

    applicationContext.close();
}

From source file:com.dinstone.jrpc.example.spring.ServiceWithSpring.java

protected static void case01() {
    ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(
            "jrpc-example-case1.xml");

    HelloService rhsv1 = (HelloService) applicationContext.getBean("rhsv1");

    try {//from ww w. j  a  v a 2s .com
        testHot(rhsv1);
    } catch (Exception e) {
        e.printStackTrace();
    }

    try {
        testSend1k(rhsv1);
    } catch (Exception e) {
        e.printStackTrace();
    }

    try {
        System.in.read();
    } catch (IOException e) {
    }

    applicationContext.close();
}