List of usage examples for org.springframework.context.support GenericXmlApplicationContext GenericXmlApplicationContext
public GenericXmlApplicationContext()
From source file:com.home.ln_spring.ch4.NonSingleton.java
public static void main(String[] args) { GenericXmlApplicationContext ctx = new GenericXmlApplicationContext(); ctx.load("classpath:app-context-xml.xml"); ctx.refresh();// ww w .j av a2s. c om String str1 = (String) ctx.getBean("nonSingleton"); String str2 = (String) ctx.getBean("nonSingleton"); System.out.println("Identity Equal?: " + (str1 == str2)); System.out.println("Value Equal:? " + str1.equals(str2)); System.out.println(str1); System.out.println(str2); }
From source file:com.home.ln_spring.ch5.jsr330.Jsr330Example.java
public static void main(String[] args) { GenericXmlApplicationContext ctx = new GenericXmlApplicationContext(); ctx.load("classpath:jsr330/jsr330.xml"); ctx.refresh();/*w ww . j a v a 2s. co m*/ MessageRenderer renderer = ctx.getBean("messageRenderer", MessageRenderer.class); renderer.render(); }
From source file:com.home.ln_spring.ch5.env.PlaceHolderSample.java
public static void main(String[] args) { GenericXmlApplicationContext ctx = new GenericXmlApplicationContext(); ctx.load("classpath:env/env.xml"); ctx.refresh();/*from www .ja v a2 s . c o m*/ AppProperty ap = ctx.getBean("appProperty", AppProperty.class); System.out.println("application.home: " + ap.getApplicationHome()); System.out.println("user.home: " + ap.getUserHome()); }
From source file:com.home.ln_spring.ch5.interaction.LoggingBeanExample.java
public static void main(String[] args) { GenericXmlApplicationContext ctx = new GenericXmlApplicationContext(); ctx.load("classpath:interaction/logging.xml"); ctx.refresh();/*from w w w. ja va 2 s. co m*/ LoggingBean bean = (LoggingBean) ctx.getBean("loggingBean"); bean.someOperation(); }
From source file:com.home.ln_spring.ch4.DeclareSpringComponents.java
public static void main(String args[]) { GenericXmlApplicationContext ctx = new GenericXmlApplicationContext(); //ctx.load("classpath:app-context-annotation.xml"); ctx.load("classpath:app-context-xml.xml"); ctx.refresh();/*from w w w . j a va2 s. c o m*/ MessageRenderer mr = ctx.getBean("messageRenderer", MessageRenderer.class); mr.render(); // Constructor injection // MessageProvider mp = ctx.getBean("messageProvider", MessageProvider.class); // System.out.println(mp.getMessage()); }
From source file:com.home.ln_spring.ch5.factory.MessageDigestrExample.java
public static void main(String[] args) { GenericXmlApplicationContext context = new GenericXmlApplicationContext(); context.load("classpath:factory/factory.xml"); context.refresh();//from w w w .j a v a 2 s . com MessageDigester digester = (MessageDigester) context.getBean("digester"); digester.digest("Hello World!"); }
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();// w ww . j av a 2s . co m GenericXmlApplicationContext child = new GenericXmlApplicationContext(); child.load("classpath:META-INF/spring/app-context-xml.xml"); child.setParent(parent); 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.HierarchicalAppContextUsage.java
public static void main(String args[]) { GenericXmlApplicationContext parent = new GenericXmlApplicationContext(); parent.load("classpath:parent.xml"); parent.refresh();/* w w w. j a va2s . c o m*/ GenericXmlApplicationContext child = new GenericXmlApplicationContext(); child.load("classpath:app-context-xml.xml"); child.setParent(parent); 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:org.springforpro.chptr5.context.MessageSourceDemo.java
public static void main(String[] args) { GenericXmlApplicationContext ctx = new GenericXmlApplicationContext(); ctx.load("classpath:appContext/messageSource.xml"); ctx.refresh();//from w w w . j av a2s . c o m 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 .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.ch5.context.MessageSourceDemo.java
public static void main(String[] args) { GenericXmlApplicationContext context = new GenericXmlApplicationContext(); context.load("classpath:appContext/messageSource.xml"); context.refresh();/* ww w . ja v a2s . co m*/ Locale english = Locale.ENGLISH; Locale czech = new Locale("cs", "CZ"); System.out.println(context.getMessage("msg", null, english)); System.out.println(context.getMessage("msg", null, czech)); System.out.println( context.getMessage("nameMsg", new Object[] { "Dynisyuk", "Vitaliy", "Vladimirovich" }, english)); }