1.与hibernate集成 <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="configLocation" value="classpath:hibernate.cfg.xml"> </property> </bean> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory"><ref bean="sessionFactory" /></property> </bean> <!--支持@Transactional标记--> <tx:annotation-driven /> <!-- 支持@AspectJ标记--> <aop:aspectj-autoproxy /> <!--以AspectJ方式定义AOP --> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="get*" read-only="true" /> <tx:method name="find*" read-only="true" /> <tx:method name="search*" read-only="true" /> <tx:method name="*" /> </tx:attributes> </tx:advice>
<!--以AspectJ方式定义AOP 第二种方法-->
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED"/>
<tx:method name="del*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="save*" propagation="REQUIRED"/>
<tx:method name="insert*" propagation="REQUIRED"/>
<tx:method name="*" read-only="true" />
</tx:attributes>
</tx:advice>
<aop:config proxy-target-class="true"> <aop:advisor pointcut="execution(* com.ssh.idao.*DAO.*(..))" advice-ref="txAdvice" /> </aop:config> <bean name="/view" class="com.ssh.struts.action.ViewAction"> </bean> 2.与ibaitis集成,只需配置jdbc事务即可 <context:component-scan base-package="com.filmdubbing.manager"/> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="${jdbc.driverClassName}" /> <property name="url" value="${jdbc.url}" /> <property name="username" value="${jdbc.username}" /> <property name="password" value="${jdbc.password}" /> <property name="initialSize" value="5" /> <property name="maxActive" value="100" /> <property name="maxIdle" value="30" /> <property name="maxWait" value="1000" /> <property name="poolPreparedStatements" value="true" /> <property name="defaultAutoCommit" value="true" /> <property name="validationQuery" value="select 1 from dual" /> <property name="testOnBorrow" value="true" /> </bean> <bean id="yzfwTM" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource" /> </bean> <tx:advice id="yzfwTA" transaction-manager="yzfwTM"> <tx:attributes> <tx:method name="get*" propagation="REQUIRED" read-only="true" rollback-for="Throwable" /> <tx:method name="find*" propagation="REQUIRED" read-only="true" rollback-for="Throwable" /> <tx:method name="*" propagation="REQUIRED" rollback-for="Throwable" /> </tx:attributes> </tx:advice> <aop:config proxy-target-class="true"> <aop:pointcut id="yzfwTO" expression="execution(* com.filmdubbing.manager..*.*(..))" /> <aop:advisor advice-ref="yzfwTA" pointcut-ref="yzfwTO" /> </aop:config>