Spring_Struts_Hibernate框架整合
来源:互联网 发布:直销源码 编辑:程序博客网 时间:2024/06/01 14:19
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">
<!-- 数据库的连接,通过外部db.properties文件 -->
<context:property-placeholder location="classpath:db.properties" />
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="${driverClass}" />
<property name="jdbcUrl" value="${jdbcUrl}" />
<property name="user" value="${user}" />
<property name="password" value="${password}" />
<property name="acquireIncrement" value="${acquireIncrement}" />
<property name="initialPoolSize" value="${initialPoolSize}" />
<property name="minPoolSize" value="${minPoolSize}" />
<property name="maxPoolSize" value="${maxPoolSize}" />
<property name="maxIdleTime" value="${maxIdleTime}" />
</bean>
<!-- 配置sessionFactory,用来代替hibernate.cfg.xml的映射部分 -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mappingResources">
<list>
<value>com/lee/bean/petDiary.hbm.xml</value>
<value>com/lee/bean/petInfo.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<value>
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.show_sql =true
hibernate.hbm2ddl.auto=update
</value>
</property>
</bean>
<!-- 事务管理器 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- 利用切面开启事务管理器,为方法开启事物,与关闭 -->
<aop:config>
<aop:pointcut id="pointcut" expression="execution(* com.lee.DaoImp.*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="pointcut" />
</aop:config>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="show*" read-only="true" />
<tx:method name="main*" read-only="true" />
<tx:method name="get*" read-only="true" />
<tx:method name="select*" read-only="true" />
</tx:attributes>
</tx:advice>
<bean id="IPetDao" class="com.lee.DaoImp.PetDaoImp">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="IPetSever" class="com.lee.SeverImp.PetSeverImp">
<property name="petDao" ref="IPetDao"></property>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">
<!-- 数据库的连接,通过外部db.properties文件 -->
<context:property-placeholder location="classpath:db.properties" />
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="${driverClass}" />
<property name="jdbcUrl" value="${jdbcUrl}" />
<property name="user" value="${user}" />
<property name="password" value="${password}" />
<property name="acquireIncrement" value="${acquireIncrement}" />
<property name="initialPoolSize" value="${initialPoolSize}" />
<property name="minPoolSize" value="${minPoolSize}" />
<property name="maxPoolSize" value="${maxPoolSize}" />
<property name="maxIdleTime" value="${maxIdleTime}" />
</bean>
<!-- 配置sessionFactory,用来代替hibernate.cfg.xml的映射部分 -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mappingResources">
<list>
<value>com/lee/bean/petDiary.hbm.xml</value>
<value>com/lee/bean/petInfo.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<value>
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.show_sql =true
hibernate.hbm2ddl.auto=update
</value>
</property>
</bean>
<!-- 事务管理器 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- 利用切面开启事务管理器,为方法开启事物,与关闭 -->
<aop:config>
<aop:pointcut id="pointcut" expression="execution(* com.lee.DaoImp.*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="pointcut" />
</aop:config>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="show*" read-only="true" />
<tx:method name="main*" read-only="true" />
<tx:method name="get*" read-only="true" />
<tx:method name="select*" read-only="true" />
</tx:attributes>
</tx:advice>
<bean id="IPetDao" class="com.lee.DaoImp.PetDaoImp">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="IPetSever" class="com.lee.SeverImp.PetSeverImp">
<property name="petDao" ref="IPetDao"></property>
</bean>
<bean id="PetAction" class="com.lee.action.MainAction">
<property name="psi" ref="IPetSever"></property>
</bean>
</beans>
properties文件
driverClass=com.mysql.jdbc.Driver
jdbcUrl=jdbc:mysql://127.0.0.1:3306/ssh
user=root
password=root
acquireIncrement=10
initialPoolSize=10
minPoolSize=3
maxPoolSize=500
maxIdleTime=1800
0 0
- Spring_Struts_Hibernate框架整合
- 框架整合
- 框架整合
- 框架整合
- 框架整合
- 框架整合
- 框架整合
- 【框架整合】三、整合mybatis
- 【框架整合】四、整合redis
- 框架整合____Spring整合hibernate
- SSH框架整合笔记
- Spring整合Struts框架
- ssh框架整合
- SSH框架整合
- SSH+DWR 框架 整合
- SSH框架整合步骤
- SSH框架的整合
- SSH框架整合步骤
- c语言数据结构1——线性表链式存储
- tigase 启用Http Rest API 问题整理
- maven updateProject的时候,pom文件报错until the update interval of central has elapsed or updates are forced
- 第十六周 项目 1 - 验证算法之(1)直接插入排序
- pg主备切换
- Spring_Struts_Hibernate框架整合
- Atitit.软件开发的几大规则,法则,与原则Principle v3
- angularJS1界面跳转
- 高德地图报错java.lang.UnsatisfiedLinkError: Native method not found
- AndroidStudio快捷键设置2
- 用纯js实现悬浮按钮组件
- 揭开Unity AssetBundle庐山真面目(二)
- Windows下安装Memcache
- TextView 显示内容时出现 ArrayIndexOutOfBoundsException 的解决方法(Android 4.1)