package com.epeer.dao;
Spring2事务管理的两种配置(XML&&标注)
}
Spring2事务管理的两种配置(XML&&标注)<?xml version="1.0" encoding="UTF-8"?>
Spring2事务管理的两种配置(XML&&标注)
<beans xmlns="http://www.springframework.org/schema/beans"
Spring2事务管理的两种配置(XML&&标注)    xmlns:xsi
="http://www.w3.org/2001/XMLSchema-instance"
Spring2事务管理的两种配置(XML&&标注)    xmlns:util
="http://www.springframework.org/schema/util"
Spring2事务管理的两种配置(XML&&标注)    xmlns:p
="http://www.springframework.org/schema/p"
Spring2事务管理的两种配置(XML&&标注)    xmlns:aop
="http://www.springframework.org/schema/aop"
Spring2事务管理的两种配置(XML&&标注)    xmlns:tx
="http://www.springframework.org/schema/tx"
Spring2事务管理的两种配置(XML&&标注)    xsi:schemaLocation
="
Spring2事务管理的两种配置(XML&&标注)http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
Spring2事务管理的两种配置(XML&&标注)http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd
Spring2事务管理的两种配置(XML&&标注)http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
Spring2事务管理的两种配置(XML&&标注)http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"

Spring2事务管理的两种配置(XML&&标注)    default-autowire
="byName">
Spring2事务管理的两种配置(XML&&标注)    
<!-- =========================================================================================== -->
Spring2事务管理的两种配置(XML&&标注)    
<!--                                       加载属性文件                                          -->    
Spring2事务管理的两种配置(XML&&标注)    
<!-- =========================================================================================== -->
Spring2事务管理的两种配置(XML&&标注)    
<bean id="jdbcConfiguration"
Spring2事务管理的两种配置(XML&&标注)        class
="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
Spring2事务管理的两种配置(XML&&标注)        
<property name="locations">
Spring2事务管理的两种配置(XML&&标注)            
<list>
Spring2事务管理的两种配置(XML&&标注)                
<value>classpath:jdbc-config.properties</value>
Spring2事务管理的两种配置(XML&&标注)            
</list>
Spring2事务管理的两种配置(XML&&标注)        
</property>
Spring2事务管理的两种配置(XML&&标注)    
</bean>
Spring2事务管理的两种配置(XML&&标注)    
<!-- =========================================================================================== -->
Spring2事务管理的两种配置(XML&&标注)    
<!--                                       配置数据源                                            -->
Spring2事务管理的两种配置(XML&&标注)    
<!-- =========================================================================================== -->
Spring2事务管理的两种配置(XML&&标注)    
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
Spring2事务管理的两种配置(XML&&标注)        destroy-method
="close" p:driverClassName="${jdbc_driver}"
Spring2事务管理的两种配置(XML&&标注)        p:url
="${jdbc_url}" p:username="${username}" p:password="${password}"/>
Spring2事务管理的两种配置(XML&&标注)    
<!-- =========================================================================================== -->
Spring2事务管理的两种配置(XML&&标注)    
<!--                                       事务配置                                              -->
Spring2事务管理的两种配置(XML&&标注)    
<!-- =========================================================================================== -->
Spring2事务管理的两种配置(XML&&标注)    
<!-- Transaction manager for a single JDBC DataSource -->
Spring2事务管理的两种配置(XML&&标注)    
Spring2事务管理的两种配置(XML&&标注)    
<bean id="transactionManager"
Spring2事务管理的两种配置(XML&&标注)        class
="org.springframework.jdbc.datasource.DataSourceTransactionManager"/>
Spring2事务管理的两种配置(XML&&标注)    
<!--                  如果采用XML配置则用下面的配置                                              -->
Spring2事务管理的两种配置(XML&&标注)    
<aop:config proxy-target-class="true">
Spring2事务管理的两种配置(XML&&标注)        
<aop:advisor pointcut="execution(* com.epeer.service.*Impl.*(..))"
Spring2事务管理的两种配置(XML&&标注)            advice-ref
="txAdvice"/>
Spring2事务管理的两种配置(XML&&标注)    
</aop:config>
Spring2事务管理的两种配置(XML&&标注)    
<tx:advice id="txAdvice" transaction-manager="transactionManager">
Spring2事务管理的两种配置(XML&&标注)        
<tx:attributes>
Spring2事务管理的两种配置(XML&&标注)            
<tx:method name="insert*" no-rollback-for="java.lang.Throwable"/>
Spring2事务管理的两种配置(XML&&标注)            
<tx:method name="remove*"/>
Spring2事务管理的两种配置(XML&&标注)            
<tx:method name="add*" no-rollback-for="java.lang.Throwable"/>
Spring2事务管理的两种配置(XML&&标注)            
<tx:method name="*" read-only="true"/>
Spring2事务管理的两种配置(XML&&标注)        
</tx:attributes>
Spring2事务管理的两种配置(XML&&标注)    
</tx:advice>
Spring2事务管理的两种配置(XML&&标注)    
<!--                  如果采用XML配置则用上面的配置                                              -->
Spring2事务管理的两种配置(XML&&标注)    
<!--                  如果采用标注则去掉上面的配置,同时加入下面一行                             -->
Spring2事务管理的两种配置(XML&&标注)    
<!--
Spring2事务管理的两种配置(XML&&标注)    <tx:annotation-driven transaction-manager="transactionManager"/>
Spring2事务管理的两种配置(XML&&标注)
Spring2事务管理的两种配置(XML&&标注)    <!-- =========================================================================================== 
-->
Spring2事务管理的两种配置(XML&&标注)    
<!--                                       事务配置                                              -->
Spring2事务管理的两种配置(XML&&标注)    
<!-- =========================================================================================== -->
Spring2事务管理的两种配置(XML&&标注)    
<!-- Transaction manager for a single JDBC DataSource -->
Spring2事务管理的两种配置(XML&&标注)    
<bean id="transactionManager"
Spring2事务管理的两种配置(XML&&标注)        class
="org.springframework.jdbc.datasource.DataSourceTransactionManager"/>
Spring2事务管理的两种配置(XML&&标注)    
<tx:annotation-driven transaction-manager="transactionManager"/>
Spring2事务管理的两种配置(XML&&标注)    
<!-- =========================================================================================== -->
Spring2事务管理的两种配置(XML&&标注)    
<!--                                       DAO配置                                               -->
Spring2事务管理的两种配置(XML&&标注)    
<!-- =========================================================================================== -->
Spring2事务管理的两种配置(XML&&标注)    
<bean id="userDao" class="com.epeer.dao.UserDaoImpl"/>
Spring2事务管理的两种配置(XML&&标注)    
<!-- =========================================================================================== -->
Spring2事务管理的两种配置(XML&&标注)    
<!--                                       Service配置                                           -->
Spring2事务管理的两种配置(XML&&标注)    
<!-- =========================================================================================== -->
Spring2事务管理的两种配置(XML&&标注)    
<bean id="userService" class="com.epeer.service.UserServiceImpl"/>
Spring2事务管理的两种配置(XML&&标注)

 采用标注的话UserServiceImpl如下

 

Spring2事务管理的两种配置(XML&&标注)package com.epeer.service;
Spring2事务管理的两种配置(XML&&标注)
Spring2事务管理的两种配置(XML&&标注)
import org.springframework.transaction.annotation.Transactional;
Spring2事务管理的两种配置(XML&&标注)
Spring2事务管理的两种配置(XML&&标注)
import com.epeer.dao.UserDao;
Spring2事务管理的两种配置(XML&&标注)
Spring2事务管理的两种配置(XML&&标注)@Transactional
}

相关文章:

  • 2021-11-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-22
  • 2021-12-25
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-06-01
  • 2021-05-17
  • 2021-12-26
  • 2021-06-17
相关资源
相似解决方案