spring开发_Annotation_注解
发布时间:2020-12-15 01:52:42 所属栏目:大数据 来源:网络整理
导读:com.b510.app.test; java.util.Arrays; org.springframework.context.ApplicationContext; org.springframework.context.support.ClassPathXmlApplicationContext; SpringTest { main(String[] args) { ApplicationContext act = ClassPathXmlApplicationCon
com.b510.app.test; java.util.Arrays; org.springframework.context.ApplicationContext; org.springframework.context.support.ClassPathXmlApplicationContext; SpringTest { main(String[] args) { ApplicationContext act = ClassPathXmlApplicationContext("beans.xml"); System.out.println(Arrays.toString(act.getBeanDefinitionNames())); } }
com.b510.service; AnimalService { getInfo(); }
com.b510.service; MeatService { String whatMeat(); }
com.b510.service.impl; javax.annotation.PostConstruct; javax.annotation.Resource; org.springframework.stereotype.Component; com.b510.service.AnimalService; com.b510.service.MeatService; @Component("cat") CatServiceBean AnimalService { age; MeatService meatService; CatServiceBean(){ System.out.println("猫类被初始化了"); } getAge() { age; } @PostConstruct @Override getInfo() { System.out.println("我是猫,我的年龄是:"+age+",我很喜欢吃"+meatService.whatMeat()); } MeatService getMeatService() { meatService; } setAge( age) { .age = age; } @Resource(name="fish") setMeatService(MeatService meatService) { .meatService = meatService; } }
com.b510.service.impl; javax.annotation.PostConstruct; javax.annotation.PreDestroy; javax.annotation.Resource; org.springframework.stereotype.Component; com.b510.service.AnimalService; com.b510.service.MeatService; @Component("dog") DogServiceBean AnimalService { age; @Resource(name = "pork") MeatService meatService; DogServiceBean() { System.out.println("狗类被初始化了"); } getAge() { age; } @PostConstruct @Override getInfo() { System.out.println("我是狗,我的年龄是:" + age + ",我很喜欢吃" + meatService.whatMeat()); } MeatService getMeatService() { meatService; } setAge( age) { .age = age; } @PreDestroy close() { System.out.println("这是Bean DogServiceBean销毁之前的方法"); } }
com.b510.service.impl; org.springframework.stereotype.Component; com.b510.service.MeatService; @Component("fish") FishServiceBean MeatService { FishServiceBean(){ System.out.println("鱼肉类被初始化了"); } @Override String whatMeat() { "鱼肉"; } }
com.b510.service.impl; org.springframework.stereotype.Component; com.b510.service.MeatService; @Component("pork") PorkServiceBean MeatService { PorkServiceBean(){ System.out.println("猪肉类被初始化了"); } @Override String whatMeat() { "猪肉"; } }
2012-3-12 21:17:39 org.springframework.context.support.AbstractApplicationContext prepareRefresh 信息: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@c1b531: display name [org.springframework.context.support.ClassPathXmlApplicationContext@c1b531]; startup date [Mon Mar 12 21:17:39 CST 2012]; root of context hierarchy 2012-3-12 21:17:39 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions 信息: Loading XML bean definitions from path resource [beans.xml] 2012-3-12 21:17:39 org.springframework.beans.factory.support.DefaultListableBeanFactory registerBeanDefinition 信息: Overriding bean definition bean 'cat': replacing [Generic bean: [com.b510.service.impl.CatServiceBean]; scope=singleton; =; lazyInit=; autowireMode=0; dependencyCheck=0; autowireCandidate=; primary=; factoryBeanName=; factoryMethodName=; initMethodName=; destroyMethodName=; defined in file [D:WordPlacespring_workspacespring_1800_Annotationbincomb510serviceimplCatServiceBean.]] with [Generic bean: [com.b510.service.impl.CatServiceBean]; scope=singleton; =; lazyInit=; autowireMode=0; dependencyCheck=0; autowireCandidate=; primary=; factoryBeanName=; factoryMethodName=; initMethodName=; destroyMethodName=; defined in path resource [beans.xml]] 2012-3-12 21:17:39 org.springframework.beans.factory.support.DefaultListableBeanFactory registerBeanDefinition 信息: Overriding bean definition bean 'dog': replacing [Generic bean: [com.b510.service.impl.DogServiceBean]; scope=singleton; =; lazyInit=; autowireMode=0; dependencyCheck=0; autowireCandidate=; primary=; factoryBeanName=; factoryMethodName=; initMethodName=; destroyMethodName=; defined in file [D:WordPlacespring_workspacespring_1800_Annotationbincomb510serviceimplDogServiceBean.]] with [Generic bean: [com.b510.service.impl.DogServiceBean]; scope=singleton; =; lazyInit=; autowireMode=0; dependencyCheck=0; autowireCandidate=; primary=; factoryBeanName=; factoryMethodName=; initMethodName=; destroyMethodName=; defined in path resource [beans.xml]] 2012-3-12 21:17:39 org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory 信息: Bean factory application context [org.springframework.context.support.ClassPathXmlApplicationContext@c1b531]: org.springframework.beans.factory.support.DefaultListableBeanFactory@587c94 2012-3-12 21:17:39 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons 信息: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@587c94: defining beans [cat,dog,fish,pork,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor]; root of factory hierarchy 猫类被初始化了 鱼肉类被初始化了 我是猫,我的年龄是:2,我很喜欢吃鱼肉 狗类被初始化了 猪肉类被初始化了 我是狗,我的年龄是:5,我很喜欢吃猪肉 [cat,org.springframework.context.annotation.internalRequiredAnnotationProcessor]
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |