<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<!-- 配置数据源 -->
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://localhost/huanglq</value>
</property>
<property name="username">
<value>root</value>
</property>
<property name="password">
<value>root</value>
</property>
</bean>
<!--bean id="dataSource"
class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>java:comp/env/jdbc/huanglq</value>
</property>
</bean-->
<!-- 定义Hibernate SessionFactory,在hibernate配置文件中用到的配置项
都可以移植到此处,包括hbm文件路径、dialect、是否显示sql语句等-->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mappingResources">
<list>
<value>com/huanglq/vo/EcCategory.hbm.xml</value>
<value>com/huanglq/vo/EcProduct.hbm.xml</value>
<value>com/huanglq/vo/EcContactinfo.hbm.xml</value>
<value>com/huanglq/vo/EcUser.hbm.xml</value>
<value>com/huanglq/vo/EcOrder.hbm.xml</value>
<value>com/huanglq/vo/EcOrderline.hbm.xml</value>
<value>com/huanglq/vo/EcPayway.hbm.xml</value>
<value>com/huanglq/vo/EcOrderstatus.hbm.xml</value>
</list>
</property>
<!--可以把上面的一堆改为下面的形式
<property name="mappingDirectoryLocations">
<list>
<value>classpath*:/com/huanglq/vo/</value>
</list>
</property>
-->
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQL5Dialect
</prop>
<prop key="hibernate.query.substitutions">
true 'Y', false 'N'
</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
<!--定义事务管理器 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- 定义事务的处理的拦截代理器 -->
<!--
1、PROPAGATION_REQUIRED :支持当前的事务,如果不存在就创建一个新的。这是最常用的选择。
2、PROPAGATION_SUPPORTS :支持当前的事务,如果不存在就不使用事务。
3、PROPAGATION_MANDATORY :支持当前的事务,如果不存在就抛出异常。
4、PROPAGATION_REQUIRES_NEW :创建一个新的事务,并暂停当前的事务(如果存在)。
5、PROPAGATION_NOT_SUPPORTED :不使用事务,并暂停当前的事务(如果存在)。
6、PROPAGATION_NEVER :不使用事务,如果当前存在事务就抛出异常。
7、PROPAGATION_NESTED :如果当前存在事务就作为嵌入事务执行,否则与PROPAGATION_REQUIRED类似。
-->
<bean id="baseTransactionProxy"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
abstract="true"><!--允许子类-->
<property name="transactionManager" ref="transactionManager" />
<property name="transactionAttributes">
<props>
<prop key="add*">PROPAGATION_REQUIRED</prop>
<prop key="create*">PROPAGATION_REQUIRED</prop>
<prop key="modify*">PROPAGATION_REQUIRED</prop>
<prop key="list*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean>
<!-- 配置产品Dao -->
<bean id="productDao" class="com.huanglq.dao.ProductHDaoImpl">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- 配置产品Bo -->
<bean id="productBo" class="com.huanglq.bo.ProductBusinessImpl">
<property name="productDao" ref="productDao" />
</bean>
<!-- 可以配置多个业务逻辑对象的事务代理器 -->
<!-- 在dao的级别进行事务管理 -->
<bean id="productDaoProxy" parent="baseTransactionProxy">
<property name="target" ref="productDao" />
</bean>
<!-- 配置用户dao -->
<bean id="userDao" class="com.huanglq.dao.UserHDaoImpl">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- 配置用户Bo -->
<bean id="userBo" class="com.huanglq.bo.UserBusinessImpl">
<property name="userDao" ref="userDao" />
</bean>
<!-- 在dao级别进行事务管理 -->
<bean id="userDaoProxy" parent="baseTransactionProxy">
<property name="target" ref="userDao" />
</bean>
<!-- 不同的用户必须使用不同的购物车 -->
<!-- 购物车应该是在session被创建的时候才创建 -->
<!-- 购物车不应该由Spring管理 -->
<!-- Sesion被创建的时候,必须创建购物车,可以使用SessionListener -->
<bean id="shoppingCartBo" class="com.huanglq.bo.ShoppingCartImpl">
</bean>
<!-- 订单管理 -->
<bean id="orderDao" class="com.huanglq.dao.OrderHDaoImpl">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="orderBo" class="com.huanglq.bo.OrderBusinessImpl">
<property name="orderDao" ref="orderDao" />
</bean>
<bean id="orderDaoProxy" parent="baseTransactionProxy">
<property name="target" ref="orderDao" />
</bean>
</beans>
下面是spring简单整合struts的文件
用的是spring2.5
spring.jar、spring-webmvc-struts.jar、commons-logging.jar
struts-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" "http://struts.apache.org/dtds/struts-config_1_3.dtd">
<struts-config>
<form-beans>
<form-bean name="userForm"
type="com.huanglq.action.form.UserForm" />
</form-beans>
<global-exceptions />
<global-forwards />
<action-mappings>
<action path="/user"
type="org.springframework.web.struts.DelegatingActionProxy"
attribute="userForm" name="userForm" scope="request"
parameter="method">
<forward name="success" path="/success.jsp" />
<forward name="fail" path="/user/login.jsp" />
</action>
</action-mappings>
<message-resources parameter="com.huanglq.resource.ApplicationResources" />
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation" value="/WEB-INF/applicationContext.xml" />
</plug-in>
</struts-config>
applicationContext.xml(配置了c3p0)
<?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.5.xsd">
<bean id="dataSourse"
class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="com.mysql.jdbc.Driver" />
<property name="jdbcUrl"
value="jdbc:mysql://localhost:3306/ssh_example" />
<property name="user" value="root"></property>
<property name="password" value="root"></property>
<!--连接池中保留的最小连接数。-->
<property name="minPoolSize">
<value>5</value>
</property>
<!--连接池中保留的最大连接数。Default: 15 -->
<property name="maxPoolSize">
<value>30</value>
</property>
<!--初始化时获取的连接数,取值应在minPoolSize与maxPoolSize之间。Default: 3 -->
<property name="initialPoolSize">
<value>10</value>
</property>
<!--当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default: 3 -->
<property name="acquireIncrement">
<value>5</value>
</property>
<!--JDBC的标准参数,用以控制数据源内加载的PreparedStatements数量。但由于预缓存的statements 属于单个connection而不是整个连接池。所以设置这个参数需要考虑到多方面的因素。 如果maxStatements与maxStatementsPerConnection均为0,则缓存被关闭。Default: 0-->
<property name="maxStatements">
<value>0</value>
</property>
<!--每60秒检查所有连接池中的空闲连接。Default: 0 -->
<property name="idleConnectionTestPeriod">
<value>60</value>
</property>
<!--定义在从数据库获取新连接失败后重复尝试的次数。Default: 30 -->
<property name="acquireRetryAttempts">
<value>30</value>
</property>
<!--获取连接失败将会引起所有等待连接池来获取连接的线程抛出异常。但是数据源仍有效 保留,并在下次调用getConnection()的时候继续尝试获取连接。如果设为true,那么在尝试 获取连接失败后该数据源将申明已断开并永久关闭。Default: false-->
<property name="breakAfterAcquireFailure">
<value>true</value>
</property>
<!--因性能消耗大请只在需要的时候使用它。如果设为true那么在每个connection提交的 时候都将校验其有效性。建议使用idleConnectionTestPeriod或automaticTestTable 等方法来提升连接测试的性能。Default: false -->
<property name="testConnectionOnCheckout">
<value>false</value>
</property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSourse" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.generate_statistics">true</prop>
<prop key="hibernate.connection.release_mode">
auto
</prop>
<prop key="hibernate.autoReconnect">true</prop>
<prop key="hibernate.jdbc.batch_size">50</prop>
</props>
</property>
<property name="mappingDirectoryLocations">
<list>
<value>classpath*:/com/huanglq/pojo/</value>
</list>
</property>
</bean>
<bean id="UserDAO" class="com.huanglq.dao.UserDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean name="/user" class="com.huanglq.action.UserAction">
<property name="userDao">
<ref bean="UserDAO" />
</property>
</bean>
</beans>
分享到:
相关推荐
struts2+spring+hibernate框架购物车
购物车用ssh框架开发,服务器,tomcat,db,oracle.ssh开发的典型例子,可供参考学习之用
Struts+hirbernate+spring 的购物车 这是一个很实用的购物车程序 。 此程序可以更清楚的了解购物车的流程以及业务逻辑 。 此项目是某一知名开源网站下的购物车程序 。 此程序适合学者学习,研究开发用途。
通过一个购物车的例子,演示了怎么整合Spring、Struts1、Hibernate,并给出了通过SpringMVC整合Struts1的一种新的方式,从而可以使得Struts1能够使用SpringMVC提供的拦截器功能,从这里也能看出SpringMVC的开放性。...
购物车系统 电子商务系统 Struts Spring Hibernate,是培训机构的一个实战项目
java购物车例子struts+hibernate+spring
可直接做毕业设计!Spring+Struts2+Hibernate框架 javaweb网络商城系统,管理员、商户、游客、购买者,商品信息,订单详情,购物车设计,完整代码_精美页面_可执行Mysql文件,系统导入Myeclipse即可执行!
这个项目为公司开发的一个商业项目,当时团队研发从需求分析阶段到代码的实现和维护经过了时长4个多月的时间才完成的,因此这个项目是花费了大量的人力和物力才完成的.因此想要下载此项目源码的读者必须用10积分才能...
1 表结构 ## 用户表 用于进行登录 create table user( id int primary key auto_increment, loginname varchar(32), password varchar(32) ); ## 商品类型表 create table goodstype( ...
基于hibernate、struts2、spring、开发项目
为了管理方便,该系统中Struts Spring的配置文件采用多模块的集成块集成开发方式完成,主要按照功能模块分配。 主要功能描述: 商品展示:主要分为商品预览、商品展示、分类检索功能。 购物车:主要分为添加...
本项目采用了Struts2作为表现层框架,Spring作为业务层框架,Hibernate作为持久层框架,确保了系统的高效、稳定和可扩展性。通过二次开发定制,用户可以根据自己的需求对系统进行功能扩展和优化,以满足不同场景下的...
目前电子商务在国内发展较为迅速,对于电子商务购物网站,购物车是其中必不可少的一个部分,设计一个功能强大、易用性好的购物车绝对是提高顾客购买兴趣和达成购买的一个重要因素。但是无论是大型电子商务网站,还是...
图 2 所示流程用 Spring Web Flow 2.0 的配置文件表示如下: 清单 1 用 Spring Web Flow 语义表达购物车流程 …… 清单 1 省略了许多技术细节,展示的只是一个业务的流程,主要是为了让大家对 Spring ...
网上商城源代码(JSP + Struts+ hibernate + spring + mysql)附带链接网上银行代码 这是我今年年初做练习时做的一个网上商城项目,基本上的功能都有 主要实现用户网上购物。主要提供了用户注册、登录、个人信息...
有各种浏览分类浏览系统,购物车系统,订单系统以及权限控制系统。使用netbeans6.5+mysql。代码的里边的默认包有一个sql文件是使用navicat导出的数据库数据。同时还有我自己编写的ActionCreator,DaoCreator等...
该系统主要采用基于B/S模式的三层数据处理结构,开发环境选用当前普遍采用的J2EE架构Spring+Hibernate+Struts框架,主要编程语言为Java,数据库为Mysql数据库,服务器方面使用Tomcat为项目主要服务器。依照软件项目...
资源名字:基于JSP+Spring+Hibernate+Struts+mysql的网上宠物销售商城系统设计与实现(源码+文档).zip 资源内容:项目全套源码+完整文档 源码说明: 全部项目源码都是经过测试校正后百分百成功运行。 包含模块: 7...
实现Spring对Hibernate和Struts的整合。目前实现的功能:(1)前台功能:用户注册,商品展示,购物车功能(商品) (2)后台功能:商品增删改查和订单管理。(3)商品搜索(搜索内容进行分词,提取关键字,模糊查询...
前端 jsp、bootstrap、jquery,后端 struts、spring、hibernate,一个模仿天猫商城的学习网站系统,产品管理、商品展示、购物车、在线结算等 毕业设计是高等教育阶段学生在完成学业前所进行的一项重要学术任务,...