关键词不能为空

当前您在: 主页 > 英语 >

Spring生命周期(代码实现,超详细)

作者:高考题库网
来源:https://www.bjmy2z.cn/gaokao
2021-02-06 02:20
tags:

-

2021年2月6日发(作者:aisle)


1.




< p>
Spring


项目



首先 创建一个简单的


spring


项目,我用的是

< br>MyEclipse10.


步骤如下:



1.1


新建


Java


项目(< /p>


MySpring





不要忘了引入


spring



jar


文件




1.2


创建包(

fe





1.3


在包下面创建以下文件




代码如下:




package fe;



import xception;


import ctory;


import ctoryAware;


import meAware;


import ableBean;


import lizingBean;


import ationContext;


import ationContextAware;



public class PersonService implements


BeanNameAware,BeanFactoryAware,


ApplicationContextAware,InitializingBean,Dispo sableBean{



public PersonService(){




n(


函数调用




}



public String getName() {




return name;



}




public void setName(String name) {




n(


调用





= name;



}




private String name;



public void sayHi(){




n(



}




public void setBeanName(String arg0) {




// TODO Auto-generated method stub




n(


调用




}



//


传 递


Bean


工厂




public void setBeanFactory(BeanFactory arg0) throws


BeansException {




// TODO Auto-generated method stub




n(< /p>


arg0)






}



public void setApplicationContext(ApplicationContext arg0)





throws BeansException {




// TODO Auto-generated method stub




n(


text arg0)


调用




}



public void afterPropertiesSet() throws Exception {




// TODO Auto- generated method stub




n(



}



//


通过注解的方法配置


init- method


方法




//@PostConstruct



public void init(){




n(


我自己的


init()


方法。。。。




}



public void destroy() throws Exception {




// TODO Auto-generated method stub




n(



}



public void MyDestory(){




n(


自己的


des


方法。




}


}



package fe;



import xception;


import


stProcessor;



public class MyBeanPostProcessor implements BeanPostProcessor {




public Object postProcessAfterInitialization(Object arg0,


String arg1)





throws BeansException {




// TODO Auto- generated method stub




n(


arg0, String arg1)




//n(arg0+< /p>


创建时间为



());




return arg0;



}




public Object postProcessBeforeInitialization(Object arg0,


String arg1)





throws BeansException {




// TODO Auto- generated method stub




n(


arg0, String arg1)




return arg0;



}



}




x ml


version


=



encoding


=



?>





<


beans


xmlns


=


< p>




xmlns:xs i


=






xmlns:context


=



t





xmlns:tx


=






xsi:schemaLocation


=


< br>eans


/schema/beans/spring- beans-2.5.x


sd







/schema/context


/schema/context/spring-context-2

-


-


-


-


-


-


-


-



本文更新与2021-02-06 02:20,由作者提供,不代表本网站立场,转载请注明出处:https://www.bjmy2z.cn/gaokao/604855.html

Spring生命周期(代码实现,超详细)的相关文章