开发环境:MyEclipse6.0+Tomcat5.0+MySQL5.0
配置环境:Struts2+Spring2+Hibernate3.1
个人推荐先配置Spring在hibernate最后Struts2.0
配置Spring2
(1)添加Spring2开发架包
①spring.jar
②struts2-spring-plugin-2.1.6.jar
(2)创建Spring配置文件applictionContext.xml,可由IDE工具实现(MyEclipse6)
选中项目SSHDemo1,右击
选择菜单“MyEclipse”选项,指向“Project Capabilities”,选择“Add Spring Capabilities”;
选择Spring版本为Spring2,JAR Libraay Installation项选“Copy...”;
点击“Next”,
选择创建方式是否创建或覆盖已存在,选中“NEW”,选择applicationContext.xml文件存放路径,点击”Browse”,创建在项目WebRoot/WEB-INF路径下,点击“OK”,
点击“Finish”,完成。
如果配置成功,这时我们在看一下项目中的文件就已经存在applicationContext.xml文件。项目下面自动导入了Spring开发支持的包。
applicationContext.xml
代码如下:
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
</beans>
下一步配置web.xml文件,添加spring监听器
添加以下代码即可:
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
(注:org.springframework.web.context.ContextLoaderListener路径在Spring.jar包下)
测试发布,Spring2开发环境配置完毕。
配置Hibernate
选择Hibernate版本为Hibernate3.1;
JAR Libraay Installation项选