一、建立一个Web Project
①点击File→New→Web Project 新建一个Web工程。
②在Project Name中输入项目名ssh,在J2EE Specification Level中选择Java EE 6.0,然后点击Finish。
二、搭建Spring3.0
①左边显示的是生成以后的Web Project 目录结构。
选择工程名(ssh),然后添加Spring。MyEclipse→Project Capabilities→Add Spring Capabilities
②Spring version选择Spring 3.0
按图选择相应的包Spring 3.0 AOP,Spring 3.0 Core,Spring 3.0 Persistence Core,Spring 3.0 Persistence JDBC,Spring 3.0 Web;JAR Library Installation里选择Copy到lib目录(避免发布到Tomcat出问题)。
③生成applicationContext.xml文件,Folder中选择WebRoot/WEB-INF,然后点击Finish。
三、搭建Hibernate3.3
①左边显示的是生成Spring以后的目录结构(文件夹上面会有个S)。
选择工程名(ssh),然后添加Hibernate。MyEclipse→Project Capabilities→Add Hibernate Capabilities
②Hibernate Specification选择Hibernate 3.3
按图选择相应的包Hibernate 3.3 Annotations & Entity Manager,Hibernate 3.3 Core;JAR Library Installation里选择Copy到lib目录(避免发布到Tomcat出问题)。
③这里统一由Spring configuration file管理Hibernate。
④选择继承的Spring配置文件(WebRoot/WEB-INF/applicationContext.xml),SessionFactory Id默认。
⑤这里配置数据库连接,这里不打勾Specify Spring DataSource connection details,点击Next。
如果要建可以在DB Browser(Windows→Show View→Other→MyEclipse Database→DB Browser)里面新建。
⑥不打勾Create SessionFactory class,点击Finish。
四、搭建Struts2.1
①左边显示的是生成Hibernate以后的目录结构,这里用Spring管理所以看不到hibernate.cfg.xml文件了。
选择工程名(ssh),然后添加Struts。MyEclipse→Project Capabilities→Add Struts Capabilities
②Struts specification里选择Struts2.1,Struts 2 filter name默认,点击Next。
③加入Struts核心包,点击Finish。
④到此SSH环境就已经搭建好了。下面开启服务看看对不对?
五、启动Tomcat服务器,看搭建成功没?
①在web.xml里面加个监听Spring。
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext*.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
②在Servers里面点击Add Deployments。这个是MyEclipse自带的TOMCAT6.0.13。
③把工程发布到Tomcat上。
④点击Run Server启动。
⑤Console控制台里面启动完成,Spring也启动起来了。
⑥打开IE输入:http://localhost:8080/ssh 正常显示环境已经没有问题,在此框架基础上可以扩展了。
备注:如果不行就是监听的问题,改成