com.b510.dao; AnimaleDao { say(); }
com.b510.dao.impl; com.b510.dao.AnimaleDao; DogDaoImpl AnimaleDao { String name; String getName() { name; } setName(String name) { .name = name; } say(){ System.out.println(name+" is a dog,he likes bone"); } }
com.b510.service; ServiceBean { myPetSay(); }
com.b510.service.impl; com.b510.dao.AnimaleDao; com.b510.service.ServiceBean; ServiceBeanImpl ServiceBean { AnimaleDao animaleDao; myPetSay(){ animaleDao.say(); } AnimaleDao getAnimaleDao() { animaleDao; } setAnimaleDao(AnimaleDao animaleDao) { .animaleDao = animaleDao; } }
com.b510.test; org.springframework.context.ApplicationContext; org.springframework.context.support.ClassPathXmlApplicationContext; com.b510.service.ServiceBean; SpringTest { main(String[] args) { ApplicationContext ctx= ClassPathXmlApplicationContext("beans.xml"); ServiceBean serviceBean=(ServiceBean) ctx.getBean("serviceDao"); serviceBean.myPetSay(); } }
2012-3-7 23:34:52 org.springframework.context.support.AbstractApplicationContext prepareRefresh 信息: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@15eb0a9: display name [org.springframework.context.support.ClassPathXmlApplicationContext@15eb0a9]; startup date [Wed Mar 07 23:34:52 CST 2012]; root of context hierarchy 2012-3-7 23:34:52 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions 信息: Loading XML bean definitions from path resource [beans.xml] 2012-3-7 23:34:52 org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory 信息: Bean factory application context [org.springframework.context.support.ClassPathXmlApplicationContext@15eb0a9]: org.springframework.beans.factory.support.DefaultListableBeanFactory@161f10f 2012-3-7 23:34:52 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons 信息: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@161f10f: defining beans [animaleDao,serviceDao]; root of factory hierarchy 哈巴 is a dog,he likes bone