packagecom.zho.service.impl;importcom.zho.dao1.IAccountDao;importcom.zho.factory.BeanFactory;importcom.zho.service.IAccountService;publicclassIAccountServiceImplimplementsIAccountService{// private IAccountDao accountDao = new IAccountDaoImpl();//从工厂中生产dao对象privateIAccountDao accountDao =(IAccountDao)BeanFactory.getBean("accountDao");@OverridepublicvoidsaveAccount(){
accountDao.saveAccount();}}
web层
packagecom.zho.ui;importcom.zho.factory.BeanFactory;importcom.zho.service.IAccountService;publicclassClient{publicstaticvoidmain(String[] args){// IAccountService as = new IAccountServiceImpl();for(int i =0; i <5; i++){//从中工厂生产service对象//由于工厂中生产的过程中,是存储在一个map中的,所以从工厂中获多个serive对象的地址位同一地址IAccountService as =(IAccountService)BeanFactory.getBean("accountService");System.out.println(as);}// as.saveAccount();}}