📄 iocmaintest.java
字号:
package test.ejb3;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.access.BeanFactoryLocator;
import org.springframework.beans.factory.access.BeanFactoryReference;
import org.springframework.beans.factory.access.SingletonBeanFactoryLocator;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
*
* @author worldheart
*
*/
public class IoCMainTest {
protected static final Log log = LogFactory.getLog(IoCMainTest.class);
public static void main(String[] args) {
ApplicationContext ac1 = new ClassPathXmlApplicationContext("ac1.xml");
//ac1作为ac2的双亲
ApplicationContext ac2 = new ClassPathXmlApplicationContext(new String[]{"ac2.xml"}, ac1);
//ac3作为ac2的双亲
ApplicationContext ac3 = new ClassPathXmlApplicationContext(new String[]{"ac3.xml"}, ac2);
//从ac3中操控ac1中的受管POJO
log.info(ac3.getBean("bi1"));
ApplicationContext ac = new ClassPathXmlApplicationContext(
new String[]{"ac1.xml","ac2.xml","ac3.xml"});
log.info(ac.getBean("bi1"));
ApplicationContext appcontext = new ClassPathXmlApplicationContext("ac.xml");
ApplicationContext appcontext1 = (ApplicationContext)appcontext.getBean("appcontext3");
log.info(appcontext1.getBean("bi1"));
//SingletonBeanFactoryLocator、ContextSingletonBeanFactoryLocator
BeanFactoryLocator bfl = SingletonBeanFactoryLocator.getInstance();
BeanFactoryReference bfr = bfl.useBeanFactory("appcontext3");
IBusinessInterface bi = (IBusinessInterface)bfr.getFactory().getBean("bi2");
log.info(bi.getStr("worldheart"));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -