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//ENbeansbeanid=userBeanclass=bean_initialization.init_interface.beans.Userpropertyname=userNamevalueEric/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//ENbeansbeanid=userBeanclass=bean_initialization.init_method.beans.Userinit-method=initMepropertyname=userNamevalueEric/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());}