spring 事务配置 的一种方法

 
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
  3. <!--
  4.     - Application context definition for PetClinic on JDBC.
  5. -->
  6. <beans>
  7.     <!-- ========================= RESOURCE DEFINITIONS ========================= -->
  8.     <!-- Configurer that replaces ${...} placeholders with values from a properties file -->
  9.     <!-- (in this case, JDBC-related settings for the dataSource definition below) -->
  10.     <!--  
  11.         <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
  12.         <property name="location" value="/WEB-INF/jdbc.properties"/>
  13.         </bean>
  14.     -->
  15.     <!-- 
  16.         Simple local DataSource that works in any environment.
  17.         This uses the JDBC DriverManager to obtain connections, and does NOT perform connection
  18.         pooling. Connection pooling is essential to all real-world applications.
  19.         This definition is good for getting started, as it introduces no dependencies beyond
  20.         the JDK, but DriverManagerDataSource is not intended for production usage.
  21.     -->
  22.     <!-- 
  23.         <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
  24.         <property name="driverClassName" value="${jdbc.driverClassName}"/>
  25.         <property name="url" value="${jdbc.url}"/>
  26.         <property name="username" value="${jdbc.username}"/>
  27.         <property name="password" value="${jdbc.password}"/>
  28.         </bean>
  29.     -->
  30.     <!--  在spring中直接配置jdbc链接
  31.     <bean id="dataSource"
  32.         class="org.springframework.jdbc.datasource.DriverManagerDataSource">
  33.         <property name="driverClassName"
  34.             value="net.sourceforge.jtds.jdbc.Driver" />
  35.         <property name="url"
  36.             value="jdbc:jtds:sqlserver://localhost:1433/wmjqxgl;SelectMethod=cursor;charset=GBK;tds=8.0;lastupdatecount=true" />
  37.         <property name="username" value="sa" />
  38.         <property name="password" value="sa" />
  39.     </bean>-->
  40.      
  41.      <!-- 通过proxool来配置数据源-->
  42.     <bean id="dataSource"
  43.         class="org.springframework.jdbc.datasource.DriverManagerDataSource">
  44.         <property name="driverClassName"
  45.             value="org.logicalcobwebs.proxool.ProxoolDriver" />
  46.         <property name="url"
  47.             value="proxool.qxgldb" />
  48.     </bean>   
  49.     <!-- 
  50.         Alternative local DataSource that works in any environment, and offers much better performance.
  51.         Uses Apache Commons DBCP for connection pooling. See Commons DBCP documentation
  52.         for the required JAR files. See the PetStore sample application also shipped with
  53.         Spring, for an example of Commons DBCP usage and the necessary build script.
  54.         Alternatively you can use another connection pool such as C3P0, similarly configured
  55.         using Spring.
  56.         A standalone connection pool such as Commons DBCP is a good choice for use outside an
  57.         application server environment, including web applications running in a web container without
  58.         JTA, or integration testing using the org.springframework.test package.
  59.     -->
  60.     <!--
  61.         <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
  62.         <property name="driverClassName" value="${jdbc.driverClassName}"/>
  63.         <property name="url" value="${jdbc.url}"/>
  64.         <property name="username" value="${jdbc.username}"/>
  65.         <property name="password" value="${jdbc.password}"/>
  66.         </bean>
  67.     -->
  68.     <!-- JNDI DataSource for J2EE environments -->
  69.     <!--
  70.         <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
  71.         <property name="jndiName" value="java:comp/env/jdbc/petclinic"/>
  72.         </bean>
  73.     -->
  74.     <!-- Transaction manager for a single JDBC DataSource (alternative to JTA) -->
  75.     <bean id="transactionManager"
  76.         class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  77.         <property name="dataSource" ref="dataSource" />
  78.     </bean>
  79.     <!-- Transaction manager that delegates to JTA (for a transactional JNDI DataSource) -->
  80.     <!--
  81.         <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"/>
  82.     -->
  83.     <bean id="baseTransactionProxy" abstract="true"
  84.         class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
  85.         <property name="transactionManager">
  86.             <ref bean="transactionManager" />
  87.         </property>
  88.         <property name="transactionAttributes">
  89.             <props>
  90.                 <prop key="create*">
  91.                     PROPAGATION_REQUIRED,-Exception
  92.                 </prop>
  93.                 <prop key="update*">
  94.                     PROPAGATION_REQUIRED,-Exception
  95.                 </prop>
  96.                 <prop key="delete*">
  97.                     PROPAGATION_REQUIRED,-Exception
  98.                 </prop>
  99.                 <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
  100.                 <prop key="retrieve*">
  101.                     PROPAGATION_REQUIRED,readOnly
  102.                 </prop>
  103.                 <prop key="*">PROPAGATION_REQUIRED,-Exception</prop>
  104.             </props>
  105.         </property>
  106.     </bean>
  107.     <!--  
  108.     通过BeanNameAutoProxyCreator来实现spring的事务控制-->
  109.     <bean
  110.         class="org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor">
  111.         <property name="transactionInterceptor"
  112.             ref="transactionInterceptor" />
  113.     </bean>
  114.         
  115.     <bean id="transactionInterceptor"
  116.         class="org.springframework.transaction.interceptor.TransactionInterceptor">
  117.         <property name="transactionManager">
  118.             <ref bean="transactionManager" />
  119.         </property>
  120.         <property name="transactionAttributes">
  121.             <props>
  122.                 <prop key="create*">
  123.                     PROPAGATION_REQUIRED,-Exception
  124.                 </prop>
  125.                 <prop key="update*">
  126.                     PROPAGATION_REQUIRED,-Exception
  127.                 </prop>
  128.                 <prop key="delete*">
  129.                     PROPAGATION_REQUIRED,-Exception
  130.                 </prop>
  131.                 <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
  132.                 <prop key="retrieve*">
  133.                     PROPAGATION_REQUIRED,readOnly
  134.                 </prop>
  135.                 <prop key="*">PROPAGATION_REQUIRED,-Exception</prop>
  136.             </props>
  137.         </property>
  138.     </bean>
  139.     
  140.     <bean
  141.         class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
  142.         <property name="beanNames">
  143.             <value>*ServiceDao</value>
  144.         </property>
  145.         <property name="interceptorNames">
  146.             <list>
  147.                 <value>transactionInterceptor</value>
  148.             </list>
  149.         </property>
  150.     </bean>
  151.     <!-- ========================= BUSINESS OBJECT DEFINITIONS ========================= -->
  152. </beans>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值