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:be.anova.course.camel.components.Main.java

public static void main(String[] args) throws Exception {
    BrokerService broker = new BrokerService();
    broker.setBrokerName("CamelComponentExercise");
    broker.setPersistent(false);//from  w w  w.  j av a2s. co m
    broker.setUseJmx(false);
    broker.start();

    ApplicationContext context = new ClassPathXmlApplicationContext("context.xml");

    Thread.sleep(60000);

    broker.stop();
}

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

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

From source file:se.patrikbergman.java.cxf.example.client.Client.java

public static void main(String args[]) throws Exception {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
            new String[] { "client-beans.xml" });
    HelloWorld client = (HelloWorld) context.getBean("client");
    String response = client.sayHi("Joe");
    System.out.println("Response: " + response);
    System.exit(0);//w  ww. j  ava 2  s .  co m
}

From source file:springjetty.HtmlParser.jetty.MyJettyApplication.java

public static void main(String[] args) throws Exception {
    ApplicationContext ctx = new ClassPathXmlApplicationContext("resources/conf/applicationContext.xml");

    //      SpringApplication.run(MyJettyApplication.class, args);
}

From source file:com.apress.prospringintegration.transform.Transformer.java

public static void main(String[] args) {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:transformer.xml");

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

    Map<String, String> customerMap = new HashMap<String, String>();
    customerMap.put("firstName", "John");
    customerMap.put("lastName", "Smith");
    customerMap.put("address", "100 State Street");
    customerMap.put("city", "Los Angeles");
    customerMap.put("state", "CA");
    customerMap.put("zip", "90064");

    Message<Map<String, String>> message = MessageBuilder.withPayload(customerMap).build();
    input.send(message);//from ww w . ja  v a2  s.  c  o m

    Message<?> reply = output.receive();
    System.out.println("received: " + reply.getPayload());
}

From source file:com.tvd.common.channel.HelloWorldExample.java

public static void main(String args[]) {
    String cfg = "channel/context.xml";
    @SuppressWarnings("resource")
    ApplicationContext context = new ClassPathXmlApplicationContext(cfg);
    MessageChannel channel = context.getBean("names", MessageChannel.class);
    Message<String> message = MessageBuilder.withPayload("World").build();
    channel.send(message);// w  ww . j  av  a 2s .c  o m
}

From source file:bankconsoleapp.console.Main.java

/**
 * @param args the command line arguments
 *//*from  www.j a  va 2  s .  co m*/
public static void main(String[] args) {

    //Injecting applicationContext to main
    ApplicationContext context = new ClassPathXmlApplicationContext("bankconsoleapp/applicationContext.xml");

    EmployeeService eS = context.getBean("EmployeeService", EmployeeService.class);
    CustomerService cS = context.getBean("CustomerService", CustomerService.class);
    SavingService sS = context.getBean("SavingService", SavingService.class);

    String userName, pass;
    Scanner in = new Scanner(System.in);
    boolean user = false;
    boolean savingRedo = false;

    do {

        System.out.println("Enter Employee ID:");
        userName = in.nextLine();
        for (Employee emp : eS.getAllEmp()) {
            if (userName.equals(emp.geteID())) {
                System.out.println("Password:");
                pass = in.nextLine();
                for (Employee em : eS.getAllEmp()) {
                    if (pass.equals(em.getPassword())) {

                        user = true;
                    }
                }
            }
        }

    } while (!user);

    long start = System.currentTimeMillis();
    long end = start + 60 * 1000; // 60 seconds * 1000 ms/sec
    int operation = 0;
    int userChoice;

    boolean quit = false;
    do {
        System.out.println("ACME Bank Saving System:");
        System.out.println("------------------------");
        System.out.println("1. Create Customer & Saving Account");
        System.out.println("2. Deposit Money");
        System.out.println("3. Withdraw Money");
        System.out.println("4. View Balance");
        System.out.println("5. Quit");
        System.out.print("Operation count: " + operation + "(Shut down at 5)");
        userChoice = in.nextInt();
        switch (userChoice) {
        case 1:

            //create customer, then saving account regard to existing customer( maximum 2 SA per Customer)
            System.out.println("Create Customer :");
            String FirstN, LastN, DoB, accNum, answer;

            Scanner sc = new Scanner(System.in);
            Customer c = new Customer();
            int saID = 0;

            System.out.println("Enter First Name:");
            FirstN = sc.nextLine();
            c.setFname(FirstN);
            System.out.println("Enter Last Name:");
            LastN = sc.nextLine();
            c.setLname(LastN);
            System.out.println("Enter Date of Birth:");
            DoB = sc.nextLine();
            c.setDoB(DoB);

            do {

                System.out.println("Creating saving acount, Enter Account Number:");
                accNum = sc.nextLine();
                c.setSA(accNum);
                c.setSavingAccounts(c.getSA());
                saID++;
                System.out.println("Create another SA? Y/N?");
                answer = sc.nextLine();
                if (answer.equals("n")) {
                    savingRedo = true;
                }
                if (saID == 2) {
                    System.out.println("Maximum Saving account reached!");
                }
            } while (!savingRedo && saID != 2);

            cS.createCustomer(c);
            operation++;

            break;
        case 2:
            // deposit

            String acNum;
            int amt;
            Scanner sc1 = new Scanner(System.in);
            System.out.println("Enter Saving Account number u wish to do deposit.");
            acNum = sc1.nextLine();
            System.out.println("Enter amount :");
            amt = sc1.nextInt();

            sS.deposit(acNum, amt);
            operation++;

            break;
        case 3:
            String acNums;
            int amts;
            Scanner sc2 = new Scanner(System.in);
            System.out.println("Enter Saving Account number u wish to do withdraw.");
            acNums = sc2.nextLine();
            System.out.println("Enter amount :");
            amts = sc2.nextInt();

            sS.withdraw(acNums, amts);
            operation++;
            break;

        case 4:
            // view
            System.out.println("Saving Account Balance:");
            System.out.println(sS.getAllSA());
            operation++;
            break;

        case 5:
            quit = true;
            break;
        default:
            System.out.println("Wrong choice.");
            break;
        }
        System.out.println();
        if (operation == 5) {
            System.out.println("5 operation reached, System shutdown.");
        }
        if (System.currentTimeMillis() > end) {
            System.out.println("Session Expired.");
        }
    } while (!quit && operation != 5 && System.currentTimeMillis() < end);
    System.out.println("Bye!");

}

From source file:com.apress.prospringintegration.wiretap.WireTapExample.java

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

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

    Map<String, String> customerMap = new HashMap<String, String>();
    customerMap.put("firstName", "John");
    customerMap.put("lastName", "Smith");
    customerMap.put("address", "100 State Street");
    customerMap.put("city", "Los Angeles");
    customerMap.put("state", "CA");
    customerMap.put("zip", "90064");

    Message<Map<String, String>> message = MessageBuilder.withPayload(customerMap).build();
    input.send(message);/* ww  w  . j  av a2 s . c  o  m*/

    Message<?> reply = output.receive();
    System.out.println("received: " + reply.getPayload());
}

From source file:com.apress.prospringintegration.transform.HeaderEnricher.java

public static void main(String[] args) {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
            "classpath:header-enricher.xml");

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

    Map<String, String> customerMap = new HashMap<String, String>();
    customerMap.put("firstName", "John");
    customerMap.put("lastName", "Smith");
    customerMap.put("address", "100 State Street");
    customerMap.put("city", "Los Angeles");
    customerMap.put("state", "CA");
    customerMap.put("zip", "90064");

    Message<Map<String, String>> message = MessageBuilder.withPayload(customerMap).build();
    input.send(message);//from ww w. j a va  2 s  .  co  m

    Message<?> reply = output.receive();
    System.out.println("received: " + reply);
}

From source file:org.springsource.greenbeans.examples.edawithspring.etailer.backoffice.Main.java

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

    ClassPathXmlApplicationContext classPathXmlApplicationContext = new ClassPathXmlApplicationContext(
            "/backoffice.xml");
    classPathXmlApplicationContext.start();

    log.debug("just launched the backoffice...");

}