Spring3.0和Hibernate3.6集成的事务控制配置方法


<?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:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<!-- 定义Proxool数据源 -->
<bean id="dataSource" class="org.logicalcobwebs.proxool.ProxoolDataSource">
<property name="driver" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"></property>
<property name="driverUrl" value="jdbc:sqlserver://localhost:1433;databaseName=NewDB;"></property>
<property name="user" value="sa"></property>
<property name="password" value="123456"></property>
<property name="maximumConnectionCount" value="3"></property>
<property name="houseKeepingTestSql" value="select getdate()"></property>
</bean>
<!-- 定义Hibernate sessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean" destroy-method="destroy">
<property name="dataSource" ref="dataSource"></property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/zywang/model/Student.hbm.xml</value>
<value>com/zywang/model/Teacher.hbm.xml</value>
</list>
</property>
</bean>
<!-- ===================================事务定义开始================================ -->
<!-- Hibernate事务管理器 -->
<bean id="hibernateTransactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<!-- 定义通知拦截方法 -->
<tx:advice id="txAdvice" transaction-manager="hibernateTransactionManager">
<tx:attributes>
<tx:method name="*" read-only="true"/>
<tx:method name="add*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="delete*" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice>
<!-- 事务拦截切面定义 -->
<aop:config>
<aop:pointcut expression="execution(* com.zywang.services.*.*(..))" id="servicesOperation"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="servicesOperation"/>
</aop:config>
<!-- ===================================事务定义结束================================ -->

<!-- ===================================定义方法调用日志开始================================ -->
<!-- 日志输出类 -->
<bean id="logAround" class="com.zywang.action.LogAround"></bean>
<!-- 定义CGLIB方式,代理指定类 -->
<aop:config proxy-target-class="true">
<aop:aspect ref="logAround">
<aop:around method="doLogAround" pointcut="execution(* com.zywang.action.*.*(..))"/>
</aop:aspect>
</aop:config>
<!-- 定义接口方式,代理指定类 -->
<aop:config>
<aop:aspect ref="logAround">
<aop:around method="doLogAround" pointcut="execution(* com.zywang.services.*.*(..))"/>
<aop:around method="doLogAround" pointcut="execution(* com.zywang.dao.*.*(..))"/>
</aop:aspect>
</aop:config>
<!-- ===================================定义方法调用日志结束================================ -->

</beans>




package com.zywang.action;

import org.apache.log4j.Logger;
import org.aspectj.lang.ProceedingJoinPoint;

/**
* @author ZYWANG
*
*/
public class LogAround {
private static Logger logger = Logger.getLogger(LogAround.class);
public Object doLogAround(ProceedingJoinPoint joinPoint) throws Throwable{
logger.info("开始"+joinPoint);
Object object = joinPoint.proceed();
logger.info("结束"+joinPoint);
return object;
}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值