1。添加jar包 (下面有所需的jar包,可下载 )
2。在web。xml中添加对struts的加载和对spring的监听( web.xml )
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>ssh</display-name>
<!-- 配置struts -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- 配置Spring -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:*.xml</param-value>
</context-param>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
3.配置hibernate文件(hibernate.cfg.xml)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>
<property name="hibernate.connection.driver_class">com.microsoft.jdbc.sqlserver.SQLServerDriver</property>
<property name="hibernate.connection.url">jdbc:microsoft:sqlserver://localhost:1433;databaseName=good</property>
<property name="hibernate.connection.username">sa</property>
<property name="hibernate.connection.password">a7788250</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<property name="hibernate.show_sql">false</property>
<property name="hibernate.format_sql">false</property>
<property name="hibernate.current_session_context_class">thread</property>
<!-- 最大连接数 -->
<property name="hibernate.c3p0.max_size">20</property>
<!-- 最小连接数 -->
<property name="hibernate.c3p0.min_size">5</property>
<!-- 获得连接的超时时间,如果超过这个时间,会抛出异常,单位毫秒 -->
<property name="hibernate.c3p0.timeout">120</property>
<!-- 最大的PreparedStatement的数量 -->
<property name="hibernate.c3p0.max_statements">100</property>
<!-- 每隔120秒检查连接池里的空闲连接 ,单位是秒-->
<property name="hibernate.c3p0.idle_test_period">120</property>
<!-- 当连接池里面的连接用完的时候,C3P0一下获取的新的连接数 -->
<property name="hibernate.c3p0.acquire_increment">2</property>
<!-- 每次都验证连接是否可用 -->
<property name="hibernate.c3p0.validate">true</property>
<mapping resource="com/zx/test/model/User.hbm.xml" />
</session-factory>
</hibernate-configuration>
4.配置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">
<!-- 配置sessionFactory -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation" value="classpath:hibernate.cfg.xml">
</property>
</bean>
<!-- 配置dao层 -->
<bean id="userDao" class="com.zx.test.dao.UserDao">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<!-- 配置service层 -->
<bean id="userService" class="com.zx.test.service.UserService">
<property name="userDao" ref="userDao"></property>
</bean>
<!-- 配置事务管理器 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<!-- 手动配置事务代理 -->
<bean id="userProxy"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="proxyTargetClass">
<value>true</value>
</property>
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
<property name="target">
<ref local="userService" />
</property>
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<!-- 配置action层 -->
<bean id="userAction" class="com.zx.test.action.UserAction" scope="prototype">
<property name="userService" ref="userProxy"></property>
</bean>
</beans>
5.配置struts.xml文件
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<include file="struts-default.xml"/>
<package name="user" extends="struts-default" namespace="/user">
<action name="userAdd" class="userAction" method="userAdd">
<result name="success">/userShow.jsp</result>
<result name="input">/index.jsp</result>
</action>
</package>
</struts>
- 大小: 6.3 KB
分享到:
相关推荐
struts2.0+spring2.5+hibernate3.0整合框架,下载导入到eclipse下即可。。启动tomcat前先修改jdbc.properties文件。由于lib文件较大,所以请自行导入相关lib包。
Struts 2 + Spring 2.0 + Hibernate 3.0整合笔记.doc
Struts 2 + Spring 2.0 + Hibernate 3.0整合笔记
开发环境myeclipse和tomcat 服务器。使用struts2.0+spring+hibernate3.0整合
struts2.0+spring2.0+hibernate3.0整合开发快速入门-4
本项目是一个对struts2.0、spring2.0和hibernate3.0的一个简单的整合,在数据层使用了hibernate和jdbc两种技术,你在学习过程中可以对比。希望对初学着有所帮助!
本文第一部分,struts和hibernate... <br>如果不懂strust2.0请先看struts2.0快速入门 如果不懂spring请先看spring快速入门实战文档 如果不懂hibernate请先看hibernate的简单应用 <br>我都有写文档提供下载
以前整合大多数为struts1.x hibernate spring 现在struts2.x也出来一阵子了,大多公司开始使用struts2.x 所以这就造就了整合问题,此系统能帮助初学都迅速进入状态,迅速上手
自己研究了一个多星期了,咨询了好多高手,也看了好几个视频,终于做成了S2SH的整合。我的平台是:MyEclipse6.0、Sql Server 2000、...给一些还像我一样处在学习struts2+spring+hibernate整合阶段的朋友做下参考。
这个Demo是本人花费周末一天时间,从网上下载到ssh框架全部所有用到的jar包,亲自编写的一个整合实例,请大家使用时对自己所用的数据库及表结构做一定的修改。
配置Struts2.0 配置Hibernate3.0 配置Spring2.5 整合Struts 整合Hibernate
sshjar-------------------------------------------------------sshjar-----------------
主要利用hibernate3.0+struts2.0 +dwr1+spring框架
开发环境myeclipse和tomcat 服务器。使用struts2.0+spring+hibernate3.0整合
这是一个helloword级的strus2.0、spring2.5、hibernate3.0的整合,仅供学习用!由于文件过大我吧 lib下的jar包去掉了!你可以自己找,也可向我索取!
自已写的,jar自已去找啊。太大了。自已写的,jar自已去找啊。太大了。
这个是一个关于在线播放音乐的ssh例子。用到struts 2.0 ,spring 2.0 , hiberante 3.0 这可是我学习ssh技术以来做的最好的一个例子了。要是有一定ssh基础的,相信你下了会有收获的。
公司在开发Struts2.0+Spring 2.0+hibernate 3.0过程中的经典实例模型.