Java--通過Spring AOP進行交易管理,java--aop

來源:互聯網
上載者:User

Java--通過Spring AOP進行交易管理,java--aop

<?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:tx="http://www.springframework.org/schema/tx"   xmlns:aop="http://www.springframework.org/schema/aop"   xsi:schemaLocation="http://www.springframework.org/schema/beans   http://www.springframework.org/schema/beans/spring-beans-3.0.xsd    http://www.springframework.org/schema/tx   http://www.springframework.org/schema/tx/spring-tx-3.0.xsd   http://www.springframework.org/schema/aop   http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">   <!-- Initialization for data source -->   <bean id="dataSource"       class="org.springframework.jdbc.datasource.DriverManagerDataSource">      <property name="driverClassName" value="com.mysql.jdbc.Driver"/>      <property name="url" value="jdbc:mysql://localhost:3306/TEST"/>      <property name="username" value="root"/>      <property name="password" value="cohondob"/>   </bean>
   <!-- Initialization for TransactionManager -->   <bean id="transactionManager"   class="org.springframework.jdbc.datasource.DataSourceTransactionManager">      <property name="dataSource"  ref="dataSource" />       </bean>
   <tx:advice id="txAdvice"  transaction-manager="transactionManager">      <tx:attributes>      <tx:method name="create"/>      </tx:attributes>   </tx:advice>   <aop:config>      <aop:pointcut id="createOperation"       expression="execution(* com.tutorialspoint.StudentJDBCTemplate.create(..))"/>      <aop:advisor advice-ref="txAdvice" pointcut-ref="createOperation"/>   </aop:config>   <!-- Definition for studentJDBCTemplate bean -->   <bean id="studentJDBCTemplate"     class="com.tutorialspoint.StudentJDBCTemplate">      <property name="dataSource"  ref="dataSource" />     </bean></beans>

 

<?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:aop="http://www.springframework.org/schema/aop"      xmlns:tx="http://www.springframework.org/schema/tx"      xmlns:context="http://www.springframework.org/schema/context"      xsi:schemaLocation="http://www.springframework.org/schema/beans                       http://www.springframework.org/schema/beans/spring-beans.xsd                       http://www.springframework.org/schema/tx                       http://www.springframework.org/schema/tx/spring-tx.xsd                       http://www.springframework.org/schema/aop                       http://www.springframework.org/schema/aop/spring-aop.xsd "  >    <bean id="transactionManager"          class="org.springframework.orm.hibernate3.HibernateTransactionManager"          abstract="false" lazy-init="default" autowire="default"          dependency-check="default">          <property name="sessionFactory">              <ref bean="sessionFactory" />          </property>      </bean>      <tx:advice id="txAdvice" transaction-manager="transactionManager">          <tx:attributes>              <tx:method name="add*" propagation="REQUIRED" />              <tx:method name="delete*" propagation="REQUIRED" />              <tx:method name="update*" propagation="REQUIRED" />              <tx:method name="add*" propagation="REQUIRED" />              <!-- <tx:method name="*" propagation="true" />-->          </tx:attributes>        </tx:advice>        <aop:config>          <aop:pointcut id="allManagerMethod"              expression="execution(* com.service.*.*(..))" />          <aop:advisor advice-ref="txAdvice"              pointcut-ref="allManagerMethod" />      </aop:config>  </beans>  

 

我解釋一下(* com.evan.crm.service.*.*(..))中幾個萬用字元的含義: 

|第一個 * —— 通配 任意傳回值類型| 
|第二個 * —— 通配 包com.evan.crm.service下的任意class| 
|第三個 * —— 通配 包com.evan.crm.service下的任意class的任意方法| 
|第四個 .. —— 通配 方法可以有0個或多個參數| 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.