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>

cn.itwuyao.demo3.AccountDaoImpl

public class AccountDaoImpl extends JdbcDaoSupport implements AccountDao {

dao的实现类要继承jdbcDaoSupport方法







原创粉丝点击