[转]spring声明式事务配置方法(五):DefaultAdvisorAutoProxyCreator

Xml代码
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2.   
  3. <beans xmlns="http://www.springframework.org/schema/beans"  
  4.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  5.     xmlns:aop="http://www.springframework.org/schema/aop"  
  6.     xmlns:tx="http://www.springframework.org/schema/tx"  
  7.     xsi:schemaLocation="  
  8.             http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd  
  9.             http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd  
  10.             http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">  
  11.     <bean id="testAction" class="test.action.Stuts2ActionTest">  
  12.         <property name="service" ref="templatesService"></property>  
  13.     </bean>  
  14.   
  15.     <bean id="templatesService"  
  16.         class="test.service.impl.TaoTemplatesServiceImpl">  
  17.         <property name="dao" ref="templatesDAO" />  
  18.     </bean>  
  19.   
  20.     <bean id="templatesDAO" class="test.dao.impl.TaoTemplatesDAOImpl">  
  21.         <property name="sessionFactory" ref="sessionFactory"></property>  
  22.     </bean>  
  23.   
  24.     <!--定义数据源-->  
  25.     <bean id="dataSource"  
  26.         class="org.apache.commons.dbcp.BasicDataSource">  
  27.         <!--   定义数据库驱动-->  
  28.         <property name="driverClassName">  
  29.             <value>oracle.jdbc.driver.OracleDriver</value>  
  30.         </property>  
  31.         <!--   定义数据库url-->  
  32.         <property name="url">  
  33.             <value>jdbc:oracle:thin:@192.168.1.96:1521:yxdb</value>  
  34.         </property>  
  35.         <!--   定义数据库用户名-->  
  36.         <property name="username">  
  37.             <value>yxuser</value>  
  38.         </property>  
  39.         <!--   定义数据库密码-->  
  40.         <property name="password">  
  41.             <value>yxuser</value>  
  42.         </property>  
  43.     </bean>  
  44.   
  45.     <!--定义一个hibernate的SessionFactory-->  
  46.     <bean id="sessionFactory"  
  47.         class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">  
  48.         <!--   定义SessionFactory必须注入DataSource-->  
  49.         <property name="dataSource">  
  50.             <ref local="dataSource" />  
  51.         </property>  
  52.         <property name="mappingResources">  
  53.             <list>  
  54.                 <!--以下用来列出所有的PO映射文件-->  
  55.                 <value>test/mapping/Tao_Templates.hbm.xml</value>  
  56.             </list>  
  57.         </property>  
  58.         <property name="hibernateProperties">  
  59.             <props>  
  60.                 <prop key="hibernate.dialect">  
  61.                     org.hibernate.dialect.Oracle10gDialect  
  62.                 </prop>  
  63.                 <prop key="hibernate.show_sql">true</prop>  
  64.                 <!--此处用来定义hibernate的SessionFactory的属性:  
  65.                     不同数据库连接,启动时选择create,update,create-drop -->  
  66.                 <prop key="hibernate.hbm2ddl.auto">update</prop>  
  67.             </props>  
  68.         </property>  
  69.     </bean>  
  70.   
  71.     <bean id="transactionManager"  
  72.         class="org.springframework.orm.hibernate3.HibernateTransactionManager">  
  73.         <property name="sessionFactory">  
  74.             <ref bean="sessionFactory" />  
  75.         </property>  
  76.     </bean>  
  77.   
  78.     <bean id="transactionInterceptor"  
  79.         class="org.springframework.transaction.interceptor.TransactionInterceptor">  
  80.         <property name="transactionManager" ref="transactionManager" />  
  81.         <property name="transactionAttributeSource">  
  82.             <value>  
  83.                 test.dao.impl.TaoTemplatesDAOImpl.add*=PROPAGATION_REQUIRED  
  84.                 test.dao.impl.TaoTemplatesDAOImpl.mod*=PROPAGATION_REQUIRED  
  85.                 test.dao.impl.TaoTemplatesDAOImpl.del*=PROPAGATION_REQUIRED  
  86.                 test.dao.impl.TaoTemplatesDAOImpl.*=readOnly  
  87.                 <!-- Add new defines here -->  
  88.             </value>  
  89.         </property>  
  90.     </bean>  
  91.   
  92.     <bean  
  93.         class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator ">  
  94.         <property name="interceptorNames">  
  95.             <list>  
  96.                 <value>transactionInterceptor</value>  
  97.                 <!-- 
  98.                     增加新的 Interceptor 
  99.                 -->  
  100.             </list>  
  101.         </property>  
  102.     </bean>  
  103.   
  104.     <!--  
  105.         删除了也能用  
  106.         <bean  
  107.         class="org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor">  
  108.         <property name="transactionInterceptor"  
  109.         ref="transactionInterceptor" />  
  110.         </bean>  
  111.     -->  
  112. </beans> 

posted on 2010-10-12 13:38  小星星☆★  阅读(334)  评论(0编辑  收藏  举报

导航