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:com.alibaba.dubbo.examples.validation.ValidationProvider.java

public static void main(String[] args) throws Exception {
    String config = ValidationProvider.class.getPackage().getName().replace('.', '/')
            + "/validation-provider.xml";
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(config);
    context.start();//from   w w w .  j  a  v a2s .co  m
    System.in.read();
}

From source file:com.apress.prospringintegration.messaging.activemq.jms.backedchannel.TicketMain.java

public static void main(String[] args) {

    String contextName = "jms-backedchannel.xml";

    ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(contextName);
    applicationContext.start();//  www.j a v a 2  s.  c  om

    TicketCreator ticketCreator = applicationContext.getBean(TicketCreator.class);
    TicketGenerator ticketGenerator = applicationContext.getBean(TicketGenerator.class);
    TicketMessageHandler ticketMessageHandler = applicationContext.getBean(TicketMessageHandler.class);

    SubscribableChannel channel = applicationContext.getBean("ticketChannel", SubscribableChannel.class);
    channel.subscribe(ticketMessageHandler);

    while (true) {
        List<Ticket> tickets = ticketGenerator.createTickets();
        for (Ticket ticket : tickets) {
            ticketCreator.openTicket(ticket);
        }
    }
}

From source file:com.edmunds.etm.agent.apache.ApacheAgentMain.java

public static void main(String[] args) {

    // Create the Spring application context
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("apache-etm-agent-context.xml");
    ctx.registerShutdownHook();/*from   w ww  .ja  v  a2 s . c  om*/

    // Run the Apache agent
    Agent agent;
    agent = (Agent) ctx.getBean("agent", Agent.class);
    agent.run();
}

From source file:com.apress.prospringintegration.App.java

public static void main(String[] args) {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:spring-context.xml");
    context.start();/*from  w  w  w  .  j av  a2  s . com*/

    MessageChannel input = (MessageChannel) context.getBean("input");
    PollableChannel output = (PollableChannel) context.getBean("output");
    input.send(MessageBuilder.withPayload("Pro Spring Integration Example").build());
    Message<?> reply = output.receive();
    System.out.println("received: " + reply);
}

From source file:com.edmunds.etm.agent.haproxy.HaProxyAgentMain.java

public static void main(String[] args) {

    // Create the Spring application context
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("ha-proxy-etm-agent-context.xml");
    ctx.registerShutdownHook();//from w w w  .j a v a2 s . co  m

    // Run the agent
    Agent agent;
    agent = (Agent) ctx.getBean("agent", Agent.class);
    agent.run();
}

From source file:com.example.customerservice.server.CustomerServiceSpringServer.java

public static void main(String args[]) throws Exception {
    new ClassPathXmlApplicationContext("server-applicationContext.xml");
    System.in.read();//from w  w  w  . j  av  a 2  s . c om
}

From source file:com.apress.prospringintegration.JmsApp.java

public static void main(String[] args) {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
            "classpath:jms-spring-context.xml");
    context.start();/*from  w ww.  j a va  2 s  .com*/

    MessageChannel input = (MessageChannel) context.getBean("input");
    PollableChannel output = (PollableChannel) context.getBean("output");
    input.send(MessageBuilder.withPayload("Pro Spring Integration Example").build());
    Message<?> reply = output.receive();
    System.out.println("received: " + reply);
}

From source file:com.apress.prospringintegration.corespring.iocbasics.BasicIoCMain.java

public static void main(String[] args) {

    ApplicationContext app = new ClassPathXmlApplicationContext("ioc_basics.xml");

    BasicPOJO basicPOJO = (BasicPOJO) app.getBean("basic-pojo");

    assert basicPOJO != null;

    System.out.println(basicPOJO.getColor());

    ColorEnum colorEnum = (ColorEnum) app.getBean("randomColor");
    System.out.println("randomColor: " + colorEnum);
    colorEnum = (ColorEnum) app.getBean("exclusiveColor");
    System.out.println("exclusiveColor: " + colorEnum);

    ColorPicker colorPicker = (ColorPicker) app.getBean(ColorPicker.class);
    assert colorPicker != null;
    System.out.println(colorPicker.getColorRandomizer().randomColor());

    BasicIoCMain.demonstrateScopes(app);

    // Custom Scope Registration with SimpleThreadScope
    ConfigurableApplicationContext configApp = (ConfigurableApplicationContext) app;
    configApp.getBeanFactory().registerScope("thread", new SimpleThreadScope());
}

From source file:com.dianping.dpsf.other.echo.EchoClient.java

/**
 * @param args//from   w ww.j  a v a2s .  co m
 * @throws Exception 
 */
public static void main(String[] args) throws Exception {
    PigeonClientMock.setServiceAddress("127.0.0.1:20001,127.0.0.1:20002");
    ApplicationContext ctx = new ClassPathXmlApplicationContext("echo-client.xml");
    IEcho s = (IEcho) ctx.getBean("echo");
    //      System.out.println(s.echo("aa"));
    //      Thread.sleep(3000);
    //      System.out.println(s.echo("aa"));
    //      System.out.println("firing");
    Random rnd = new Random(System.currentTimeMillis());

    List<String[]> hostList = new ArrayList<String[]>();
    hostList.add(new String[] { "127.0.0.1", "20001", "1" });
    PigeonClientMock.getSc().onServiceHostChange("http://service.dianping.com/echoService", hostList);

    int i = 0;
    while (i < 100) {
        try {
            System.out.println(s.echo("aa"));
        } catch (Exception e) {
            System.out.println("EEEEEEEEEEEEEEEEEEEEEEE");
        }
        Thread.sleep(2000);
        if (i == 1) {
            System.out.println("+++++++++++++++++++adding 20002++++++++++++++++");
            hostList = new ArrayList<String[]>();
            hostList.add(new String[] { "127.0.0.1", "20001", "1" });
            hostList.add(new String[] { "127.0.0.1", "20002", "1" });
            PigeonClientMock.getSc().onServiceHostChange("http://service.dianping.com/echoService", hostList);
        }
        if (i == 5) {
            System.out.println("+++++++++++++++++++adding 20003++++++++++++++++");
            hostList = new ArrayList<String[]>();
            hostList.add(new String[] { "127.0.0.1", "20001", "1" });
            hostList.add(new String[] { "192.168.32.111", "20003", "1" });
            PigeonClientMock.getSc().onServiceHostChange("http://service.dianping.com/echoService", hostList);
        }
        if (i == 10) {
            System.out.println("--------------------change wt------------");
            PigeonClientMock.getSc().onHostWeightChange("127.0.0.1", 2);
        }
        i++;
    }

}

From source file:siia.jms.GatewayDemo.java

public static void main(String[] args) {
    ApplicationContext context = new ClassPathXmlApplicationContext("siia/jms/gateways.xml");
    MessageChannel toJMS = context.getBean("toJMS", MessageChannel.class);
    PollableChannel jmsReplies = context.getBean("jmsReplies", PollableChannel.class);
    MessagingTemplate template = new MessagingTemplate();
    template.convertAndSend(toJMS, "echo");
    Object response = template.receiveAndConvert(jmsReplies);
    System.out.println("response: " + response);
}