近斷時間在看Spring(夏昕的開發指南),試著在Eclipse中試試,沒想不懂還就是不懂啊,第1個例子都沒整出來,后來才弄明白是那個bean.xml沒寫對。往后看了幾頁才曉得,我的Eclipse3.1.1裝了MyEclipse4.0.2GA,但是那個里面的XML(for Template)中模板只有4個,有WEB和Structs的,沒有Spring,于是就有了這個念頭,自己加一個模板進去。這樣以后開發就不用記那樣條目了。在Eclipse中新建XML文件: 已安裝了MyEclipse插件,新建中在MyEclipse分支下有個XML,點擊XML(from Template)利用其自帶模板新建. 現舉例加入Spring的bean.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中向導中出現的項目 2.現在手工進行更改配置文件 在其中加入: xml.template.5=Templates/Spring.xml xml.template.5.label=XML template for a Spring file 意為添加一項,模板文件是templates目錄下的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的內容是照書上抄的。
Powered by: BlogJava Copyright © 大大毛
果然是不能想得太好。