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

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

Introduction

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

Prototype

public void load(String... resourceLocations) 

Source Link

Document

Load bean definitions from the given XML resources.

Usage

From source file:com.home.ln_spring.ch10.sample.ContactSummarySample.java

public static void main(String[] args) {
    GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
    ctx.load("classpath:ch10/app-context.xml");
    ctx.refresh();/*from w w  w  .ja  v  a 2  s . c  om*/

    // ? ?   ?  .
    //        ContactSummaryUntypeImpl contactSummaryUntypeImpl = 
    //                ctx.getBean("contactSummaryUntype", ContactSummaryUntypeImpl.class);
    //        
    //        contactSummaryUntypeImpl.displayAllContactSummary();

    ContactSummaryService contactSummaryService = ctx.getBean("contactSummaryService",
            ContactSummaryService.class);

    List<ContactSummary> contacts = contactSummaryService.findAll();

    for (ContactSummary contactSummary : contacts) {
        System.out.println(contactSummary);
    }
}

From source file:com.home.ln_spring.ch4.xml.BeanNameAliasing.java

public static void main(String args[]) {
    GenericXmlApplicationContext context = new GenericXmlApplicationContext();
    context.load("classpath:app-context-xml.xml");
    context.refresh();/*w  w  w.j a v  a 2s . c om*/

    String str1 = (String) context.getBean("name1");
    String str2 = (String) context.getBean("name2");
    String str3 = (String) context.getBean("name3");
    String str4 = (String) context.getBean("name4");
    String str5 = (String) context.getBean("name5");
    String[] alias = (String[]) context.getAliases("name1");

    System.out.println(str1 == str2);
    System.out.println(str2 == str3);
    System.out.println(str3 == str4);
    System.out.println(str4 == str5);
    System.out.println(str1 == str5);
    System.out.println(Arrays.asList(alias));
}

From source file:com.home.ln_spring.ch10.sample.SpringJpaSample.java

public static void main(String args[]) {
    GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
    ctx.load("classpath:ch10/spring-data-app-context.xml");
    ctx.refresh();// w  w  w  .j av  a2s .  c om

    ContactService contactService = ctx.getBean("springJpaContactService", ContactService.class);

    // Find all contatcs
    List<Contact> contacts = contactService.findAll();
    listContacts(contacts);

    // Find contact by name
    contacts = contactService.findByFirstName("Scott");
    listContacts(contacts);
    // Find contact by first name and last name
    contacts = contactService.findByFirstNameAndLastName("John", "Smith");
    listContacts(contacts);
}

From source file:com.home.ln_spring.ch4.xml.InjectSimple.java

public static void main(String args[]) {
    GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
    ctx.load("classpath:app-context-xml.xml");
    ctx.refresh();/*from   w  ww.  j  a va 2  s  .  c  o  m*/

    InjectSimple simple = (InjectSimple) ctx.getBean("injectSimple");
    System.out.println(simple);
}

From source file:com.home.ln_spring.ch4.xml.InjectSimpleSpel.java

public static void main(String args[]) {
    GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
    ctx.load("classpath:app-context-xml.xml");
    ctx.refresh();//from   ww  w.jav a  2s.co m
    InjectSimpleSpel spel = (InjectSimpleSpel) ctx.getBean("injectSimpleSpel");

    System.out.println(spel);
}

From source file:com.mycompany.springtest03.CollectionInjection.java

public static void main(String[] args) {
    GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
    ctx.load("classpath:META-INF/spring/app-context-xml.xml");
    ctx.refresh();//from ww  w. j ava  2 s . com
    CollectionInjection instance = (CollectionInjection) ctx.getBean("injectCollection");
    instance.displayinfo();
}

From source file:com.home.ln_spring.ch4.annotation.CollectionInjection.java

public static void main(String args[]) {
    GenericXmlApplicationContext context = new GenericXmlApplicationContext();
    context.load("classpath:app-context-annotation.xml");
    context.refresh();/*w ww. j  a  v  a 2  s .c om*/

    CollectionInjection instance = (CollectionInjection) context.getBean("injectCollection");
    instance.displayInfo();
}

From source file:com.home.ln_spring.ch4.annotation.InjectSimpleSpel.java

public static void main(String args[]) {
    GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
    ctx.load("classpath:app-context-annotation.xml");
    ctx.refresh();//from  w  ww  .j  av a 2  s .co m

    InjectSimpleSpel spel = (InjectSimpleSpel) ctx.getBean("injectSimpleSpel");

    System.out.println(spel);
}

From source file:com.home.ln_spring.ch4.autowiring.Target.java

public static void main(String[] args) {
    GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
    ctx.load("classpath:autowiring.xml");
    ctx.refresh();/*  w w w.j  a v  a  2  s .co  m*/

    Target target = null;
    System.out.println("Using byName:\n");
    target = (Target) ctx.getBean("targetByName");
    System.out.println("\nUsing byType:\n");
    target = (Target) ctx.getBean("targetByType");
    System.out.println("\nUsing constructor:\n");
    target = (Target) ctx.getBean("targetConstructor");
}

From source file:com.home.ln_spring.ch5.lifecycle.DestructiveBean.java

public static void main(String[] args) {
    GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
    ctx.load("classpath:lifecycle/disposeMethod.xml");
    ctx.refresh();//from w  w  w.ja v a2  s .  co m

    DestructiveBean bean = (DestructiveBean) ctx.getBean("destructiveBean");
    System.out.println("Calling destroy()");
    ctx.destroy();
    System.out.println("Called destroy()");
}