spring中调用bean

1、使用BeanWrapper

HelloWorld hw=new HelloWorld(); 
BeanWrapper bw=new BeanWrapperImpl(hw); 
bw.setPropertyvalue(”msg”,”HelloWorld”); 
system.out.println(bw.getPropertyCalue(”msg”)); 

2、使用BeanFactory

InputStream is=new FileInputStream(”config.xml”); 
XmlBeanFactory factory=new XmlBeanFactory(is); 
HelloWorld hw=(HelloWorld) factory.getBean(”HelloWorld”); 
system.out.println(hw.getMsg()); 

3、使用ApplicationConttext

ApplicationContext actx=new FleSystemXmlApplicationContext(”config.xml”); 
HelloWorld hw=(HelloWorld) actx.getBean(”HelloWorld”); 
System.out.println(hw.getMsg());

你可能感兴趣的:(spring)