欢迎来到天天文库
浏览记录
ID:39361312
大小:296.37 KB
页数:9页
时间:2019-07-01
《Spring生命周期(代码实现,超详细)资料》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、1.创建Spring项目首先创建一个简单的spring项目,我用的是MyEclipse10.步骤如下:1.1新建Java项目(MySpring)不要忘了引入spring的jar文件1.2创建包(com.xcm.beanlife)1.3在包下面创建以下文件代码如下:PersonService.javapackagecom.xcm.beanlife;importorg.springframework.beans.BeansException;importorg.springframework.beans.factory.Bea
2、nFactory;importorg.springframework.beans.factory.BeanFactoryAware;importorg.springframework.beans.factory.BeanNameAware;importorg.springframework.beans.factory.DisposableBean;importorg.springframework.beans.factory.InitializingBean;importorg.springframework.contex
3、t.ApplicationContext;importorg.springframework.context.ApplicationContextAware;publicclassPersonServiceimplementsBeanNameAware,BeanFactoryAware,ApplicationContextAware,InitializingBean,DisposableBean{publicPersonService(){System.out.println("(1)PersonService()函数调用
4、");}publicStringgetName(){returnname;}publicvoidsetName(Stringname){System.out.println("(2)setName(Stringname)调用");this.name=name;}privateStringname;publicvoidsayHi(){System.out.println("Hi"+name);}publicvoidsetBeanName(Stringarg0){//TODOAuto-generatedmethodstubSy
5、stem.out.println("(3)setBeanName调用"+arg0);}//传递Bean工厂publicvoidsetBeanFactory(BeanFactoryarg0)throwsBeansException{//TODOAuto-generatedmethodstubSystem.out.println("(4)setBeanFactory(BeanFactoryarg0)调用"+arg0);}publicvoidsetApplicationContext(ApplicationContextarg0
6、)throwsBeansException{//TODOAuto-generatedmethodstubSystem.out.println("(5)setApplicationContext(ApplicationContextarg0)调用"+arg0);}publicvoidafterPropertiesSet()throwsException{//TODOAuto-generatedmethodstubSystem.out.println("(6)afterPropertiesSet()");}//通过注解的方法配
7、置init-method方法//@PostConstructpublicvoidinit(){System.out.println("(7)我自己的init()方法。。。。");}publicvoiddestroy()throwsException{//TODOAuto-generatedmethodstubSystem.out.println("(8)destroy().......");}publicvoidMyDestory(){System.out.println("(8)MyDestroy().......自己的
8、des方法。");}}MyBeanPostProcessor.javapackagecom.xcm.beanlife;importorg.springframework.beans.BeansException;importorg.springframework.beans.factory.config
此文档下载收益归作者所有