您的位置:首页 > 编程语言 > Java开发

MyEclipse手工添加spring XML文件模板

2013-06-15 19:55 267 查看
近断时间在看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"
"http://www.springframework.org/dtd/spring-beans.dtd">
<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的内容是照书上抄的。

原文出处:http://www.blogjava.net/tw-ddm/articles/34402.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: