spring事务管理—配置文件
来源:互联网 发布:wifi mac地址修改器 编辑:程序博客网 时间:2024/05/27 00:27
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"
xmlns:context="http://www.springframework.org/schema/context"
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.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<context:component-scan base-package="cn.itwuyao"/>
<!-- 读取属性的文件 -->
<context:property-placeholder location="classpath:db.properties"/>
<!-- 配置C3P0连接池 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${jdbc.driverClass}"></property>
<property name="jdbcUrl" value="${jdbc.jdbcUrl}"></property>
<property name="user" value="${jdbc.user}"></property>
<property name="password" value="${jdbc.password}"></property>
</bean>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"></property>
</bean>
<bean id="accountService" class="cn.itwuyao.demo3.AccountServiceImpl">
<property name="accountDao" ref="accountDao"></property>
</bean>
<bean id="accountDao" class="cn.itwuyao.demo3.AccountDaoImpl">
<property name="dataSource" ref="dataSource"></property>
</bean>
<!-- 进行事务管理 -->
<!-- 平台事务管理器 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean>
<!-- 事务的通知 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="*" read-only="false" propagation="REQUIRED"/>
<tx:method name="find*" read-only="true" isolation="DEFAULT" propagation="SUPPORTS"/>
</tx:attributes>
</tx:advice>
<!-- AOP的事务增强 -->
<aop:config>
<aop:pointcut expression="execution(* cn.itwuyao.demo3.*ServiceImpl.*(..))" id="pt1"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="pt1"/>
</aop:config>
</beans>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
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.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<context:component-scan base-package="cn.itwuyao"/>
<!-- 读取属性的文件 -->
<context:property-placeholder location="classpath:db.properties"/>
<!-- 配置C3P0连接池 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${jdbc.driverClass}"></property>
<property name="jdbcUrl" value="${jdbc.jdbcUrl}"></property>
<property name="user" value="${jdbc.user}"></property>
<property name="password" value="${jdbc.password}"></property>
</bean>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"></property>
</bean>
<bean id="accountService" class="cn.itwuyao.demo3.AccountServiceImpl">
<property name="accountDao" ref="accountDao"></property>
</bean>
<bean id="accountDao" class="cn.itwuyao.demo3.AccountDaoImpl">
<property name="dataSource" ref="dataSource"></property>
</bean>
<!-- 进行事务管理 -->
<!-- 平台事务管理器 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean>
<!-- 事务的通知 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="*" read-only="false" propagation="REQUIRED"/>
<tx:method name="find*" read-only="true" isolation="DEFAULT" propagation="SUPPORTS"/>
</tx:attributes>
</tx:advice>
<!-- AOP的事务增强 -->
<aop:config>
<aop:pointcut expression="execution(* cn.itwuyao.demo3.*ServiceImpl.*(..))" id="pt1"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="pt1"/>
</aop:config>
</beans>
cn.itwuyao.demo3.AccountDaoImpl
public class AccountDaoImpl extends JdbcDaoSupport implements AccountDao {
dao的实现类要继承jdbcDaoSupport方法
阅读全文
0 0
- spring事务管理—配置文件
- spring+hibernate事务管理配置文件
- 使用Spring配置文件实现事务管理
- SSH结合spring事务管理配置文件
- 使用Spring配置文件实现事务管理
- spring学习(十)—事务管理(配置文件方式实现)
- spring mvc+hibernate 实现事务管理(配置文件版)
- spring mvc+hibernate 实现事务管理(配置文件版)
- 14-spring的事务管理(配置文件实现)
- Spring—事务管理
- Spring事务管理——AOP注解事务管理
- Spring学习笔记(16)----使用Spring配置文件实现事务管理
- Spring学习笔记(18)----使用Spring配置文件实现事务管理
- Spring学习笔记(18)----使用Spring配置文件实现事务管理
- Spring配置文件详解三:Spring声明式事务管理
- Spring事务管理——慕课网
- Spring事务管理—AOP/Annotation
- Spring in Action — 事务管理
- 超级账本(hyperledger)生产多节点部署
- 限产环保压力陡增,钢铁有色机会来临20191116
- Ajax基础知识
- 安装cuDNN
- 1068. 万绿丛中一点红(20)
- spring事务管理—配置文件
- python:格式化字符串,format
- data-toggle与data-target是什么作用
- 岗前实训第三天 MySQL的查询
- Mkaefile的基本编写
- linux的目录结构
- MWC(2) Multiwii初学者详细准备
- CMB标量功率谱第二个谱指数跑动项n(2)跑动带来的影响
- 1016. 部分A+B (15)(版本二)