spring开发_spring构造注入Bean
发布时间:2020-12-15 01:52:30 所属栏目:大数据 来源:网络整理
导读: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.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
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |