Example usage for org.springframework.context.support GenericXmlApplicationContext GenericXmlApplicationContext

List of usage examples for org.springframework.context.support GenericXmlApplicationContext GenericXmlApplicationContext

Introduction

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

Prototype

public GenericXmlApplicationContext(String... resourceLocations) 

Source Link

Document

Create a new GenericXmlApplicationContext, loading bean definitions from the given resource locations and automatically refreshing the context.

Usage

From source file:org.resthub.rpc.example.EchoServer.java

public static void main(String[] args) throws Exception {
    //        CachingConnectionFactory connectionFactory = new CachingConnectionFactory("localhost", 5672);
    //        connectionFactory.setUsername("guest");
    //        connectionFactory.setPassword("guest");
    ////  w ww .  j  a v a 2s  .c  o m
    //        Endpoint endpoint = new Endpoint(new EchoServiceImpl());
    //        endpoint.setConnectionFactory(connectionFactory);
    //        endpoint.run();
    //        
    //        connectionFactory.destroy();

    new GenericXmlApplicationContext("classpath:/applicationContext-server.xml");
}

From source file:com.xoriant.akka.mongodb.bulkimport.main.Application.java

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

    ApplicationContext ctx = new GenericXmlApplicationContext("springconfig.xml");

    final ActorSystem _system = ActorSystem.create("FileImportApp");

    final ActorRef mongoInsertionActor = _system.actorOf(Props.create(MongoInsertionActor.class, ctx)
            .withRouter(new RoundRobinPool(INSERTION_ACTOR_POOL_SIZE)));

    final ActorRef fileReaderActor = _system
            .actorOf(Props.create(FileReaderActor.class, mongoInsertionActor, BATCH_SIZE));
    String path = Thread.currentThread().getContextClassLoader().getResource("NameList.csv").getFile();
    fileReaderActor.tell(path, ActorRef.noSender());
    Thread.sleep(5000);// w ww  .  j a  va 2s  .  c o  m
    _system.shutdown();

}

From source file:org.resthub.rpc.example.EchoClient.java

public static void main(String[] args) throws Exception {
    //        CachingConnectionFactory connectionFactory = new CachingConnectionFactory("localhost", 5672);
    //        connectionFactory.setUsername("guest");
    //        connectionFactory.setPassword("guest");
    //        /*from w  w w .  j a  v a 2s .  com*/
    //        AMQPProxyFactory factory = new AMQPProxyFactory();
    //        factory.setConnectionFactory(connectionFactory);
    //        factory.setReadTimeout(3000);
    //        EchoService service = factory.create(EchoService.class);
    //        
    //        System.out.println(service.echo("Hello AMQP!"));
    //        connectionFactory.destroy();

    GenericXmlApplicationContext context = new GenericXmlApplicationContext(
            "classpath:/applicationContext-client.xml");

    EchoService service = (EchoService) context.getBean("echoService");
    System.out.println(service.echo("Hello AMQP!"));

    context.close();

}

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;//from   w  w  w  .j  av  a2s .c  o  m
    ContestantDao contestantDao = (ContestantDao) factory.getBean("contestantDao");

    List<ContestantData> list = contestantDao.findContestant("0");
    if (list == null || list.size() == 0) {
        contestantDao.insertContestant("foo", "bar", "0");
    }
    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.rcaspar.fitbitbat.App.java

/**
 * Program entry point./*  w  ww. j  av  a2 s .c om*/
 *
 * @param args CLI args
 */
public static void main(final String[] args) {
    log.debug("main() - args={}", Arrays.asList(args));
    final Args arguments = new Args();
    try {
        new JCommander(arguments, args);

        final GenericXmlApplicationContext applicationContext = new GenericXmlApplicationContext(
                "classpath:application-context.xml");
        applicationContext.registerShutdownHook();
        applicationContext.start();

        final Package appPackage = App.class.getPackage();
        log.info("=== {} v.{} started ===", appPackage.getImplementationTitle(),
                appPackage.getImplementationVersion());

        final FitBitBat fitBitBat = applicationContext.getBean(FitBitBat.class);
        if (fitBitBat.checkCredentials(arguments.getPin())) {
            fitBitBat.startAsync();
        } else {
            log.error("Bad pin: {}", arguments.getPin());
        }
    } catch (final OAuthException ex) {
        System.err.println(ex.getMessage());
        System.exit(1);
    } catch (final ParameterException ex) {
        new JCommander(arguments).usage();
        System.exit(-1);
    } catch (final Exception ex) {
        log.error("Cannot startup", ex);
        System.exit(-2);
    }
}

From source file:org.helios.ember.Boot.java

/**
 * Main boot//from www .  j a  v a 2s  .co m
 * @param args none
 */
public static void main(String[] args) {
    LOG.info("Booting Ember.sftp Server");
    try {
        APPCTX = new GenericXmlApplicationContext(
                new FileSystemResource("./src/main/resources/META-INF/jetty.xml"));
        LOG.info("Ember.sftp Server Up");
        Thread.currentThread().join();
    } catch (Exception ex) {
        LOG.error("Failed to boot Ember.sftp Server", ex);
        System.exit(-1);
    }
}

From source file:org.kew.rmf.core.CoreApp.java

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

    // Some arguments possibly want to be picked up from the command-line
    CommandLine line = getParsedCommandLine(args);

    // where is the work directory that contains the design configuration as well
    // as the data files?
    String workDir = ".";
    if (line.hasOption("d"))
        workDir = line.getOptionValue("d").trim();
    // the name of the core configuration file that contains the dedup/match design
    // NOTE this is relative to the working directory
    String configFileName = "config.xml";
    if (line.hasOption("c"))
        configFileName = line.getOptionValue("c").trim();
    String dedupDesign = "file:" + new File(new File(workDir), configFileName).toPath();

    runEngineAndCache(new GenericXmlApplicationContext(dedupDesign));

}

From source file:ezbake.example.ezmongo.EzMongoSpringDataSampleClient.java

public static void main(String[] args)
        throws VisibilityParseException, ClassificationConversionException, EzMongoBaseException {

    // For XML/*from   w  ww  . j a  v  a 2s. c  o m*/
    ApplicationContext ctx = new GenericXmlApplicationContext("springDataConfig.xml");

    // For Annotation
    //ApplicationContext ctx =
    //        new AnnotationConfigApplicationContext(SpringMongoConfig.class);
    MongoOperations mongoOperation = (MongoOperations) ctx.getBean("mongoTemplate");

    User user = new User("mkyong", "password123");

    // Here, we would insert the security tagging fields into the DBObject by calling a utility class (RedactHelper.java).
    Visibility vis = new Visibility();
    // Convert CAPCO to Accumulo-style boolean expression string and set it in the Visibility object.
    String booleanExpressionString = ClassificationUtils.getAccumuloVisibilityStringFromCAPCO("SECRET");
    vis.setFormalVisibility(booleanExpressionString);
    RedactHelper.setSecurityFieldsInDBObject(user, vis, "testAppId");

    // Also set the Name field in the User
    Name name = new Name("testFirstName", "testLastName");
    Visibility nameVis = new Visibility();
    nameVis.setFormalVisibility(booleanExpressionString);
    RedactHelper.setSecurityFieldsInDBObject(name, nameVis, "testAppId");

    user.setName(name);

    // Call the Provenance service to get a unique ID for the document -
    //   the unique ID would be used for the Purge feature.

    // save
    mongoOperation.save(user);

    // now user object got the created id.
    System.out.println("1. user : " + user);

    // query to search user
    Query searchUserQuery = new Query(Criteria.where("username").is("mkyong"));

    // find the saved user again.
    User savedUser = mongoOperation.findOne(searchUserQuery, User.class);
    System.out.println("2. find - savedUser : " + savedUser);

}

From source file:it.dontesta.spring.example.config.SpringContext.java

public static GenericApplicationContext getContext() {
    if (ctx == null) {
        synchronized (LOCK) {
            ctx = new GenericXmlApplicationContext("applicationContext.xml");
        }/* w w  w.j a va 2s .  c  om*/
    }
    return ctx;
}

From source file:org.activiti.spring.SpringConfigurationHelper.java

public static ProcessEngine buildProcessEngine(URL resource) {
    log.debug(//from   w w w . ja va  2  s  . c o m
            "==== BUILDING SPRING APPLICATION CONTEXT AND PROCESS ENGINE =========================================");

    ApplicationContext applicationContext = new GenericXmlApplicationContext(new UrlResource(resource));
    Map<String, ProcessEngine> beansOfType = applicationContext.getBeansOfType(ProcessEngine.class);
    if ((beansOfType == null) || (beansOfType.isEmpty())) {
        throw new ActivitiException("no " + ProcessEngine.class.getName()
                + " defined in the application context " + resource.toString());
    }

    ProcessEngine processEngine = beansOfType.values().iterator().next();

    log.debug(
            "==== SPRING PROCESS ENGINE CREATED ==================================================================");
    return processEngine;
}