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

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

Introduction

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

Prototype

public ClassPathXmlApplicationContext(String... configLocations) throws BeansException 

Source Link

Document

Create a new ClassPathXmlApplicationContext, loading the definitions from the given XML files and automatically refreshing the context.

Usage

From source file:edu.berkeley.path.next.ResultsProcessor.ResultsProcessorApp.java

public static void main(String[] args) throws Exception {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("results-processor.xml");
    context.start();//from ww w .  ja  va 2s  . c  o m

    final Logger logger = LogManager.getLogger(ResultsProcessorApp.class.getName());

    logger.info("ResultsProcessorApp initialized ");

}

From source file:com.alibaba.dubbo.examples.async.AsyncConsumer.java

public static void main(String[] args) throws Exception {
    String config = AsyncConsumer.class.getPackage().getName().replace('.', '/') + "/async-consumer.xml";
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(config);
    context.start();//  ww w  .java 2  s  . c om

    final AsyncService asyncService = (AsyncService) context.getBean("asyncService");

    Future<String> f = RpcContext.getContext().asyncCall(new Callable<String>() {
        public String call() throws Exception {
            return asyncService.sayHello("async call request");
        }
    });

    System.out.println("async call ret :" + f.get());

    RpcContext.getContext().asyncCall(new Runnable() {
        public void run() {
            asyncService.sayHello("oneway call request1");
            asyncService.sayHello("oneway call request2");
        }
    });

    System.in.read();
}

From source file:com.morty.podcast.writer.PodCastCreationRunner.java

/**
 * This is the main runner for this application.
 * It takes the parameter of the spring context file to use,
 * then looks up the generator (which should be populated with the right
 * parameter values and in the classpath) and runs it.
 * @param spring context file to use/*from w w w. ja va2  s  .  c  o  m*/
 */
public static void main(String[] args) {
    try {
        //Get the spring bean, and run
        m_logger.info("Starting PodCast Generator");
        String springFile = args[0];
        m_logger.info("Using Spring File [" + springFile + "]");

        final ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(springFile);
        final PodCastGenerator pcg = (PodCastGenerator) ctx.getBean(PodCastConstants.PODCAST_GENERATOR_BEAN);

        pcg.generatePodCast();
    } catch (Exception e) {
        m_logger.error("Unable to get bean from spring context. Please confirm file and bean details.", e);
    }

}

From source file:com.apress.prospringintegration.messagehistory.MessageHistoryApp.java

public static void main(String[] args) {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
            "classpath:messagehistory/message-history-context.xml");

    MessageChannel input = context.getBean("input", MessageChannel.class);

    PollableChannel output = context.getBean("output", PollableChannel.class);
    input.send(MessageBuilder.withPayload("Pro Spring Integration Example").build());
    Message<?> reply = output.receive();

    Iterator<Properties> historyIterator = reply.getHeaders()
            .get(MessageHistory.HEADER_NAME, MessageHistory.class).iterator();

    while (historyIterator.hasNext()) {
        Properties properties = historyIterator.next();
        System.out.println(properties);
    }/*ww w.j a v a 2s.  co m*/

    System.out.println("received: " + reply);
}

From source file:com.javacreed.examples.flyway.Example2.java

public static void main(final String[] args) {
    Example2.LOGGER.debug("Loading the spring context");
    try (ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
            "/META-INF/application-context.xml")) {
        final JdbcTemplate jdbcTemplate = context.getBean(JdbcTemplate.class);

        Example2.LOGGER.debug("Name      | Surname");
        Example2.LOGGER.debug("-----------------------");
        jdbcTemplate.query("SELECT * FROM `sample_table`", new RowCallbackHandler() {
            @Override//from w  w w  .  j  av  a 2 s  .  com
            public void processRow(final ResultSet resultSet) throws SQLException {
                Example2.LOGGER.debug(String.format("%-10s| %-10s", resultSet.getString("name"),
                        resultSet.getString("surname")));
            }
        });
        Example2.LOGGER.debug("-----------------------");
    }
}

From source file:com.dangdang.ddframe.rdb.sharding.example.config.spring.SpringNamespaceWithAssignedDataSourceMain.java

public static void main(final String[] args) throws SQLException {
    // CHECKSTYLE:ON
    ApplicationContext applicationContext = new ClassPathXmlApplicationContext(
            "META-INF/applicationContextWithAssignedDataSource.xml");
    OrderService service = applicationContext.getBean(OrderService.class);
    service.insert();//from w w w. ja  v a  2 s.c  o  m
    service.select();
    service.delete();
    service.select();

    ConfigService configService = applicationContext.getBean(ConfigService.class);
    configService.select();
}

From source file:com.ponysdk.impl.spring.MainSpring.java

public static void main(final String[] args) {
    final String serverConfigLocation = System.getProperty(SpringApplicationManager.SERVER_CONFIG_LOCATION,
            "classpath:etc/server_application.xml");

    new ClassPathXmlApplicationContext(serverConfigLocation);
}

From source file:com.apress.prospringintegration.social.mail.PopMail.java

public static void main(String[] args) throws Exception {
    ApplicationContext context = new ClassPathXmlApplicationContext("/spring/mail/pop-mail.xml");

    DirectChannel inputChannel = context.getBean("inputChannel", DirectChannel.class);

    inputChannel.subscribe(new MessageHandler() {
        public void handleMessage(Message<?> message) throws MessagingException {
            LOG.info("Message: " + message);
        }/*from  w ww.j a  va  2s .c  om*/
    });
}

From source file:com.apress.prospringintegration.social.mail.ImapMail.java

public static void main(String[] args) throws Exception {
    ApplicationContext context = new ClassPathXmlApplicationContext("/spring/mail/imap-mail.xml");

    DirectChannel inputChannel = context.getBean("inputChannel", DirectChannel.class);

    inputChannel.subscribe(new MessageHandler() {
        public void handleMessage(Message<?> message) throws MessagingException {
            LOG.info("Message: " + message);
        }//from  ww  w  .  j a  va2s.c  om
    });
}

From source file:com.fpmislata.banco.presentation.BancoService.java

/**
 * @param args the command line arguments
 *///  w  ww  .  j  a v  a 2 s  .c  o  m
public static void main(String[] args) throws SQLException, ClassNotFoundException, BussinessException {

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

    //        EntidadBancariaDAO entidadBancariaDAO = context.getBean(EntidadBancariaDAO.class);
    //        EntidadBancaria entidadBancaria;
    //
    //        entidadBancaria = entidadBancariaDAO.get(4);
    //
    //        System.out.println(entidadBancaria.getIdEntidadBancaria()
    //                + " " + entidadBancaria.getNombre()
    //                + " " + entidadBancaria.getCodigoEntidad()
    //                + " " + entidadBancaria.getFechaCreacion()
    //                + " " + entidadBancaria.getDireccion()
    //                + " " + entidadBancaria.getCif());

    SucursalBancariaDAO sucursalBancariaDAO = context.getBean(SucursalBancariaDAO.class);
    SucursalBancaria sucursalBancaria = new SucursalBancaria();

    sucursalBancaria.setIdSucursalBancaria(1);
    sucursalBancaria.setNombreSucursal("Bancaixa");
    sucursalBancaria.setDireccion("C/Pelayo");
    sucursalBancaria.setDirector("Joan Manuel");
    sucursalBancaria.setTelefono("964320058");
    sucursalBancaria.setFechaApertura(null);
    sucursalBancariaDAO.insert(sucursalBancaria);

    //       List<EntidadBancaria> entidadesBancarias;
    //       entidadesBancarias = entidadBancariaDAO.findByName("Caixabank");
    //       
    //       for (EntidadBancaria entidad : entidadesBancarias) {
    //                System.out.println(entidad.getIdEntidadBancaria()+ "  " + entidad.getNombre() +
    //                        "  " + entidad.getCodigoEntidad()+ "  " + entidad.getFechaCreacion() +
    //                        "  " + entidad.getDireccion() + "  " + entidad.getCif());
    //            }
    //       EntidadBancaria entidadBancaria = new EntidadBancaria();
    //       entidadBancaria.setIdEntidadBancaria(2);
    //       entidadBancaria.setNombre("Bankia");
    //       entidadBancaria.setCodigoEntidad("778B");
    //       entidadBancaria.setFechaCreacion(null);
    //       entidadBancaria.setDireccion("C/Juan Varelles");
    //       entidadBancaria.setCif("002");
    //       
    //       entidadBancariaDAO.update(entidadBancaria);
}