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() 

Source Link

Document

Create a new GenericXmlApplicationContext that needs to be #load loaded and then manually #refresh refreshed .

Usage

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();//ww w .j  a  v  a  2  s . c  o  m

    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.ch4.mi.lookupDemo.java

public static void main(String args[]) {
    GenericXmlApplicationContext context = new GenericXmlApplicationContext();
    context.load("classpath:lookup.xml");
    DemoBean abstractDemoBean = (DemoBean) context.getBean("abstractLookupBean");
    DemoBean standardDemoBean = (DemoBean) context.getBean("standardLookupBean");
    displayInfo(standardDemoBean);// w  w w.  j  a va  2  s .c  om
    displayInfo(abstractDemoBean);
}

From source file:com.home.ln_spring.ch5.profile.ProfileXmlConfigExample.java

public static void main(String[] args) {

    GenericXmlApplicationContext context = new GenericXmlApplicationContext();
    context.getEnvironment().setActiveProfiles("highschool");
    context.load("classpath:profile/*-config.xml");
    context.refresh();/*from  w w  w .j  av  a  2s. co  m*/

    FoodProviderService foodProviderService = context.getBean("foodProviderService", FoodProviderService.class);

    List<Food> lunchSet = foodProviderService.provideLunchSet();

    for (Food food : lunchSet) {
        System.out.println("Food: " + food.getName());
    }

}

From source file:com.home.ln_spring.ch8.sample.JdbcContactSfDaoSample.java

public static void main(String[] args) {
    GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
    ctx.load("classpath:ch8/app-context-sf.xml");
    ctx.refresh();//www.  java2  s  . c  o  m

    ContactSfDao contactSfDao = ctx.getBean("contactSfDao", ContactSfDao.class);

    System.out.println(contactSfDao.getFirstNameById(1));
}

From source file:com.home.ln_spring.ch5.factory.AccessingFactoryBeans.java

public static void main(String[] args) {
    GenericXmlApplicationContext context = new GenericXmlApplicationContext();

    context.load("classpath:factory/factory.xml");
    context.refresh();// w w  w  .  j  a va  2  s  . c o  m

    MessageDigest digest = (MessageDigest) context.getBean("shaDigest");

    MessageDigestFactoryBean factoryBean = (MessageDigestFactoryBean) context.getBean("&shaDigest");

    try {
        MessageDigest shaDigest = factoryBean.getObject();
        System.out.println(shaDigest.digest("HELLO WORLD!".getBytes()));
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.home.ln_spring.ch4.mi.MethodReplacementExample.java

public static void main(String args[]) {
    GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
    ctx.load("classpath:replacement.xml");
    ctx.refresh();//  www  . ja v a 2s  . com

    ReplacementTarget replacementTarget = (ReplacementTarget) ctx.getBean("replacementTarget");
    ReplacementTarget standardTarget = (ReplacementTarget) ctx.getBean("standardTarget");

    displayInfo(replacementTarget);
    displayInfo(standardTarget);
}

From source file:com.home.ln_spring.ch5.interaction.ShutdownHookBeanExample.java

public static void main(String[] args) {
    GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
    ctx.load("classpath:interaction/shutdownHook.xml");
    ctx.refresh();//from ww  w.  j av a  2  s.  c  om
    DestructiveBean bean = (DestructiveBean) ctx.getBean("destructiveBean");
    //  bean.destroy();
}

From source file:com.home.ln_spring.ch4.inheritance.SimpleBean.java

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

    SimpleBean parent = (SimpleBean) ctx.getBean("inheritParent");
    SimpleBean child = (SimpleBean) ctx.getBean("inheritChild");

    System.out.println("Parent: " + parent + "\n");
    System.out.println("Child: " + child + "\n");
}

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

public static void main(String args[]) {
    GenericXmlApplicationContext context = new GenericXmlApplicationContext();
    context.load("classpath:app-context-xml.xml");
    context.refresh();/*from   w ww .ja v a2  s .  co  m*/

    InjectRef ir = (InjectRef) context.getBean("injectRef");

    System.out.println(ir);
}

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 ww .j ava2s .  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);
}