锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<description>Spring Bean Configuration Sample</description>
<bean
id="TheAction" 鈶?BR>
class="net.xiaxin.spring.qs.UpperAction" 鈶?BR>
singleton="true" 鈶?BR>
init-method="init" 鈶?BR>
destroy-method="cleanup" 鈶?BR>
depends-on="ActionManager" 鈶?BR>
>
<property name="message">
<value>HeLLo</value> 鈶?BR>
</property>
<property name="desc">
<null/>
</property>
<property name="dataSource">
<ref local="dataSource"/> 鈶?BR>
</property>
</bean>
<bean
id="dataSource"
class="org.springframework.jndi.JndiObjectFactoryBean"
>
<property name="jndiName">
<value>java:comp/env/jdbc/sample</value>
</property>
</bean>
</beans>
InputStream is = new FileInputStream("beans.xml");
XmlBeanFactory factory = new XmlBeanFactory(is);
Action action = (Action) factory.getBean("TheAction");
ApplicationContext ac = new FileSystemXmlApplicationContext("beans.xml");
Action action = (Action)ac.getBean("TheAction");
鍐嶆湁閲岄潰鎻愬埌鏈夆滅儹甯冪講鈥濈殑鍚嶈瘝錛屽簲璇ュ氨絳夊悓浜庯細
public class MyProperties
{
private String fileName = null;
private File propFile = null;
private long lastModified ;
public MyProperties(String fileName)
{
this.fileName = fileName;
}
private void loadPropFile()
{
this.propFile = new File(this.fileName);
}
private boolean isChanged()
{
boolean changed = false;
if(this.propFile.lastModified() != this.lastModified)
{
changed = true;
}
return changed;
}
public Object getProp(String propName)
{
if(isChanged())
{
this.loadPropFile();
}
.;
}
}
浜嬩歡浼犳挱鏈哄埗錛?BR> 鍩轟簬瑙傚療鑰呮ā寮忕殑瀹炵幇銆?BR> 鐢盇pplicationContext璐熻矗閫氱煡鍏ㄩ儴瀹炵幇浜咥pplicationListener鎺ュ彛鐨凚ean錛屽簲璇ユ槸涓嶈兘瀹炵幇鍒嗙被閫氱煡鐨勩?BR> 鍦ㄤ緥瀛愪腑浣跨敤浜唅nstanceof榪欑被鐨勭被鍨嬪垽鏂紝灝哃istener涓嶦vent鐗㈢墷鎸備綇浜嗭紝鎰熻涓嶆槸寰堢埥銆?BR> 鎴戠殑鎯蟲硶鏄細鍙湪ApplictionContext涓畾涔変竴涓狝pplictionListener錛岃瀹冨厖褰撳垎鍙戝櫒鍜岀己鐪丒vent澶勭悊鍣ㄧ殑瑙掕壊錛涘湪ActionEvent涔嬩笂鍐嶅皝涓涓帴鍙ctionEventEx錛屾墿灞曚竴涓帴鍙etEvnetType錛岃鍏ㄩ儴鐨凙ctionEvent瀹炰緥閮藉疄鐜拌嚜ActionEventEx鎺ュ彛銆傚茍鍦ˋpplictionListener涓疄鐜頒竴涓狟eanFactory錛屾牴鎹瓵ctionEvent鐨勫疄渚嬶紝寮鴻漿鑷矨ctionEventEx錛屽彇寰梕ventType錛屽啀浠嶢pplictionContext涓彇寰楀搴旂殑Bean鏉ュ鐞嗕簨浠躲?/FONT>
]]>
]]>
鍦‥clipse涓柊寤篨ML鏂囦歡:
宸插畨瑁呬簡MyEclipse鎻掍歡,鏂板緩涓湪MyEclipse鍒嗘敮涓嬫湁涓猉ML,鐐瑰嚮XML(from Template)鍒╃敤鍏惰嚜甯︽ā鏉挎柊寤?
鐜頒婦渚嬪姞鍏pring鐨刡ean.xml閰嶇疆鏂囦歡鐨勬ā鏉?
1.鎵撳紑鐩綍 myeclipse\eclipse\plugins\com.genuitec.eclipse.wizards_4.0.1
鍏朵腑娑夊強鏂囦歡涓?templates.properties,榪欐槸涓涓ā鏉跨殑閰嶇疆鏂囦歡
鎵撳紑鍙互瑙佸埌:
# HTML Templates
xml.template.1=Templates/Xml.xml
xml.template.1.label=Default XML template
xml.template.2=Templates/WebXml.xml
xml.template.2.label=XML template for a web.xml file
xml.template.3=Templates/WebXmlStruts.xml
xml.template.3.label=XML template for a web.xml file with Struts
xml.template.4=Templates/StrutsConfig.xml
xml.template.4.label=XML template for a struts-config.xml file
榪欐牱(39-47琛?.榪欐棦涓哄湪Eclipse涓悜瀵間腑鍑虹幇鐨勯」鐩?BR> 2.鐜板湪鎵嬪伐榪涜鏇存敼閰嶇疆鏂囦歡
鍦ㄥ叾涓姞鍏?
xml.template.5=Templates/Spring.xml
xml.template.5.label=XML template for a Spring file
鎰忎負娣誨姞涓欏?妯℃澘鏂囦歡鏄痶emplates鐩綍涓嬬殑spring.xml鏂囦歡
3.鍔犲叆妯℃澘鏂囦歡
鍦?Templates鐩綍涓嬫柊寤轟竴涓?Spring.xml"鏂囦歡:
#---------------------------------------------#
# <aw:description>Template for a WebXml file for Spring</aw:description>
# <aw:version>1.0</aw:version>
# <aw:date>02/22/2006</aw:date>
# <aw:author>Tw DDM</aw:author>
#---------------------------------------------#
<?xml version="1.0" encoding="<aw:encoding/>"?>
<!DOCTYPE web-app PUBLIC "-//SPRING//DTD BEAN//EN"
" <beans>
<description>This a description</description>
<bean
id="TheAction"
class="net.ddm.MyAction"
singleton="true"
init-method="init"
destory-method="close"
depends-on="ActionManager"
>
<property name="message">
<value>HeLLo</value>
</property>
<property name="desc">
<null/>
</property>
<property name="dataSource">
<ref local="dataSource"/>
</property>
</bean>
<bean
id="dataSource"
class="org.springframework.jndi.JndiObjectFactoryBean"
>
<property name="jndiName">
<value>java:comp/env/jdbc/sample</value>
</property>
</bean>
</beans>
4.瀹屾垚.閲嶅叆Eclipse鍗沖彲瑙佸埌鏁堟灉
榪欎釜XML鐨勫唴瀹規槸鐓т功涓婃妱鐨勩?/FONT>