第六章Spring-Bean初始化方案

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

Bean初始化方案初始化接口方案Bean开发:publicclassUserimplementsInitializingBean{privateStringuserName;publicvoidafterPropertiesSet()throwsException{this.userName=Google;}publicStringgetUserName(){returnuserName;}publicvoidsetUserName(StringuserName){this.userName=userName;}}初始化接口方案Bean的配置没有任何特殊的地方。如下:?xmlversion=1.0encoding=UTF-8?!DOCTYPEbeansPUBLIC-//SPRING//DTDBEAN//ENbeansbeanid=userBeanclass=bean_initialization.init_interface.beans.Userpropertyname=userNamevalueEric/value/property/bean/beans初始化接口方案业务逻辑:publicstaticvoidmain(String[]args){ApplicationContextac=newFileSystemXmlApplicationContext(./src/bean_initialization/init_interface/config/config.xml);//取得一个实例Useruser=(User)ac.getBean(userBean);System.out.println(user.getUserName());}初始化方法方案Bean开发:publicclassUser{privateStringuserName;publicvoidinitMe(){this.userName=BaiDu;}publicStringgetUserName(){returnuserName;}publicvoidsetUserName(StringuserName){this.userName=userName;}}初始化方法方案Bean配置:?xmlversion=1.0encoding=UTF-8?!DOCTYPEbeansPUBLIC-//SPRING//DTDBEAN//ENbeansbeanid=userBeanclass=bean_initialization.init_method.beans.Userinit-method=initMepropertyname=userNamevalueEric/value/property/bean/beans初始化方法方案业务逻辑:publicstaticvoidmain(String[]args){ApplicationContextac=newFileSystemXmlApplicationContext(./src/bean_initialization/init_method/config/config.xml);//取得一个实例Useruser=(User)ac.getBean(userBean);System.out.println(user.getUserName());}

1 / 7
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功