SSH配置初学笔记

来源:互联网 发布:理发店收费软件 编辑:程序博客网 时间:2024/05/23 19:19

1.版本选择MyEclipse 6.5搭建SSH时,使用Struts1.2 + Spring2.0 + Hibernate3.1。
步骤:
 1.创建Web Project,选择Java EE 5.0;
 2.对项目添加Struts支持,选择Struts 1.2;
 3.对项目添加Spring支持,选择Spring 2.0,选择自MyEclipse Libraries添加库支持,并且添加Spring 2.0 Core Libraries, Spring 2.0 Web Libraries,将Spring的配置文件放置WebRoot/WEB-INF目录下;
 4.在MyEclipse Hibernate Prespective中配置好数据库连接后,对项目添加Hibernate支持,选择Hibernate 3.1,选择自MyEclipse Libraries添加库支持,并且添加Hibernate 3.1 Core Libraries, Hibernate 3.1 Advanced Support Libraries, Spring 2.0 Persistence Core Libraries, Spring 2.0 Persistence JDBC Libraries,选择Hibernate configuration file,在最后一步中不选择Create SessionFactory Class;

2.配置文件
使用Struts框架来启动Spring和Hibernate。
在struts-config.xml中写入
<controller
 processorClass="org.springframework.web.struts.DelegatingRequestProcessor" />

<message-resources ... />

<plug-in
 className="org.springframework.web.struts.ContextLoaderPlugIn">
 <set-property property="contextConfigLocation"
 value="/WEB-INF/springContext-*.xml" />
 </plug-in>
格式注意,在message-resources之前写controller,之后写plug-in。

把Spring的配置文件分割成自定义的文件,分别是springContext-common.xml, springContext-bean.xml, springContext-action.xml
springContext-common.xml中只配置sessionFactory的class。
springContext-bean.xml中注入hibernatedao中的dao, 以及使用这些dao的biz。

<bean id=... class=...>
 <property name=...>
 <ref bean=...></ ref>
 </ property>
</ bean>

springContext-action.xml中注入struts的action,以及引用的biz。

<bean name=... class=...>
 <property name=...>
 <ref bean=...></ ref>
 </ property>
</ bean>


以上借助MyEclipse 6.5,SSH初步搭建完成。

注:以上皆为个人初学笔记,没有任何技术参考价值,请勿抄袭效仿,防止误导,后果自负。

原创粉丝点击