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

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

Introduction

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

Prototype

@Override
    public void refresh() throws BeansException, IllegalStateException 

Source Link

Usage

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

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

    System.out.println(ir);//from   w  w w .  j a  v  a2s . c  om
}

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

    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.mycompany.springtest02.HierarchicalAppContextUsage.java

public static void main(String[] args) {
    GenericXmlApplicationContext parent = new GenericXmlApplicationContext();
    parent.load("classpath:META-INF/spring/parent.xml");
    parent.refresh();
    GenericXmlApplicationContext child = new GenericXmlApplicationContext();
    child.load("classpath:META-INF/spring/app-context-xml.xml");
    child.setParent(parent);//from w ww.j a v  a  2s  . c om
    child.refresh();
    SimpleTarget target1 = (SimpleTarget) child.getBean("target1");
    SimpleTarget target2 = (SimpleTarget) child.getBean("target2");
    SimpleTarget target3 = (SimpleTarget) child.getBean("target3");
    System.out.println(target1.getVal());
    System.out.println(target2.getVal());
    System.out.println(target3.getVal());
}

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

public static void main(String args[]) {
    GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
    ctx.load("classpath:app-context-annotation.xml");
    ctx.refresh();

    InjectSimple simple = (InjectSimple) ctx.getBean("injectSimple");
    System.out.println(simple);/*ww  w.  j a v  a 2s  . c o  m*/
}

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

    // ? ?   ?  .
    //        ContactSummaryUntypeImpl contactSummaryUntypeImpl = 
    //                ctx.getBean("contactSummaryUntype", ContactSummaryUntypeImpl.class);
    //        /* www . j av a  2  s  . c  om*/
    //        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.ch5.factory.AccessingFactoryBeans.java

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

    context.load("classpath:factory/factory.xml");
    context.refresh();

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

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

    try {/*from w ww .  ja v  a  2  s  .  c o  m*/
        MessageDigest shaDigest = factoryBean.getObject();
        System.out.println(shaDigest.digest("HELLO WORLD!".getBytes()));
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.mycompany.mavenproject3.xml.ConstructorConfusion.java

public static void main(String[] args) {
    GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
    ctx.load("classpath:META-INF/spring/app-context-xml.xml");
    ctx.refresh();
    ConstructorConfusion cc = (ConstructorConfusion) ctx.getBean("constructorConfusion");
    System.out.println(cc);//  w  w w.jav a2s. c  om
}

From source file:org.springforpro.chptr5.context.MessageSourceDemo.java

public static void main(String[] args) {
    GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
    ctx.load("classpath:appContext/messageSource.xml");
    ctx.refresh();

    Locale english = Locale.ENGLISH;
    Locale russian = new Locale("ru", "RU");

    System.out.println("English msg: " + ctx.getMessage("msg", null, english));
    System.out.println("Russian msg: " + ctx.getMessage("msg", null, russian));
    System.out//from  w  w w. j a  v  a2  s . co  m
            .println("English nameMsg" + ctx.getMessage("nameMsg", new Object[] { "Clarence", "Ho" }, english));
    //      ResourceBundleMessageSource source = new ResourceBundleMessageSource();
    //      StaticMessageSource source = new StaticMessageSource();
    //      source.setBasename("appContext/labels");
    //      System.out.println(source.getMessage("msg", null, russian) );
    //      System.out.println(source.getMessage("msg", null, english) );
    //      Object[] os = new Object[] {"One", "two"};
    //      System.out.println(source.getMessage("nameMsg", new Object[] {"wut", "in my butt"}, english));      
}

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

    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.xml.InjectSimple.java

public static void main(String args[]) {
    GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
    ctx.load("classpath:app-context-xml.xml");
    ctx.refresh();

    InjectSimple simple = (InjectSimple) ctx.getBean("injectSimple");
    System.out.println(simple);//from   www.ja va2  s. com
}