最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

AOP之事務(wù)管理<aop:advisor>的兩種配置方式

 更新時間:2021年11月24日 08:51:04   作者:Simon_liu94  
這篇文章主要介紹了AOP之事務(wù)管理<aop:advisor>的兩種配置方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教

AOP事務(wù)管理<aop:advisor>兩種配置方式

方式一

@transactionManagerbean.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="com.wanho.java150"/>
     <context:property-placeholder location="classpath*:jdbc.properties"/>
     <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
         <property name="driverClassName" value="${jdbc.driverClassName}"/>
         <property name="url" value="${jdbc.url}"/>
         <property name="username" value="${jdbc.username}"/>
         <property name="password" value="${jdbc.password}"/>
    </bean>
     <!--spring 提供 jdbc 幫助類-->
     <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
         <property name="dataSource" ref="dataSource"/>
     </bean>
    
     <!--基于@Transactional-->
     <!--事務(wù)管理器-->
     <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
         <property name="dataSource" ref="dataSource"/>
     </bean>
     <tx:annotation-driven />    
</beans>

ServiceImpl

在service實(shí)現(xiàn)類的最外層或者具體方法上添加@Transactional注解

@Service
//@Transactional
public class CustomerServiceImpl implements CustomerService {
    @Autowired
    private CustomerDAO customerDAO ;
    @Autowired
    private LoginLogDAO loginLogDAO ;
    @Transactional
    @Override
    public Customer login(String account, String pswd) {
        return null;
    }
}

方式二

bean.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="com.wanho.java150"/>
     <context:property-placeholder location="classpath*:jdbc.properties"/>
     <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
         <property name="driverClassName" value="${jdbc.driverClassName}"/>
         <property name="url" value="${jdbc.url}"/>
         <property name="username" value="${jdbc.username}"/>
         <property name="password" value="${jdbc.password}"/>
    </bean>
     <!--spring 提供 jdbc 幫助類-->
     <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
         <property name="dataSource" ref="dataSource"/>
     </bean>
    
     <!--jdbc 事務(wù)管理配置基于xml-->
      <!--事務(wù)管理器-->
     <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
         <property name="dataSource" ref="dataSource"/>
     </bean>
     <!--事務(wù)隔離級別-->
     <tx:advice id="txAdvice" transaction-manager="txManager">
         <tx:attributes>
             <!--還可以添加回滾、只讀等標(biāo)簽配置-->
             <tx:method name="*" />
         </tx:attributes>
     </tx:advice>
     <!--業(yè)務(wù)層 使用 事務(wù)切面-->
     <aop:config>
         <aop:pointcut id="servicePointcut" expression="execution(* com.wanho.java150.service.impl.CustomerServiceImpl.*(..))"/>
         <aop:advisor advice-ref="txAdvice" pointcut-ref="servicePointcut"/>
     </aop:config>
</beans>

hibernate事務(wù)配置Aop aop:advisor模式

<!-- 使用HibernateTransactionManager管理hibernate事務(wù) -->
    <bean id="txManager"
    class="org.springframework.orm.hibernate3.HibernateTransactionManager">
         <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>
        
    <!-- 創(chuàng)建事務(wù)規(guī)則 -->
    <!-- 表示我們要控制事務(wù)的地方,如果方法名開頭是add、update和delete,那么使用REQUIRED事務(wù)傳播方式。那么其他的方法使用REQUIRED事務(wù)傳播方式,并且是只讀 -->
    <tx:advice id="txAdvice" transaction-manager="txManager">
        <tx:attributes>
           <tx:method name="add*" propagation="REQUIRED"
          rollback-for="Exception" />
          <tx:method name="delete*" propagation="REQUIRED"
          rollback-for="Exception" />
          <tx:method name="update*" propagation="REQUIRED"
          rollback-for="Exception" />
          <tx:method name="*" propagation="REQUIRED" read-only="true" />
       </tx:attributes>
    </tx:advice>
    <!-- 告知事務(wù)的切入點(diǎn) -->
    <aop:config>
    <aop:advisor advice-ref="txAdvice" pointcut="execution(* com.tiema..service..*.*(..))" />
    </aop:config>

以上為個人經(jīng)驗(yàn),希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • springboot application.yml使用@@pom文件配置問題

    springboot application.yml使用@@pom文件配置問題

    這篇文章主要介紹了springboot application.yml使用@@pom文件配置問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-07-07
  • Java反轉(zhuǎn)數(shù)組輸出實(shí)例代碼

    Java反轉(zhuǎn)數(shù)組輸出實(shí)例代碼

    這篇文章主要給大家介紹了關(guān)于Java反轉(zhuǎn)數(shù)組輸出以及利用Java實(shí)現(xiàn)字符串逆序輸出的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-01-01
  • Java報(bào)錯Non-terminating?decimal?expansion解決分析

    Java報(bào)錯Non-terminating?decimal?expansion解決分析

    這篇文章主要為大家介紹了Java報(bào)錯Non-terminating?decimal?expansion解決方案及原理分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-09-09
  • spring-boot讀取props和yml配置文件的方法

    spring-boot讀取props和yml配置文件的方法

    本篇文章主要介紹了spring-boot讀取props和yml配置文件的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-12-12
  • Spring實(shí)戰(zhàn)之容器中的工程Bean用法示例

    Spring實(shí)戰(zhàn)之容器中的工程Bean用法示例

    這篇文章主要介紹了Spring實(shí)戰(zhàn)之容器中的工程Bean用法,結(jié)合實(shí)例形式分析了Sring框架容器中的工程Bean相關(guān)配置、使用操作技巧,需要的朋友可以參考下
    2019-11-11
  • Java如何利用狀態(tài)模式(state pattern)替代if else

    Java如何利用狀態(tài)模式(state pattern)替代if else

    這篇文章主要給大家介紹了關(guān)于Java如何利用狀態(tài)模式(state pattern)替代if else的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-11-11
  • springboot整合mongodb使用詳解

    springboot整合mongodb使用詳解

    MongoDB是一個文檔數(shù)據(jù)庫(以?JSON?為數(shù)據(jù)模型),由C++語言編寫,旨在為WEB應(yīng)用提供可擴(kuò)展的高性能數(shù)據(jù)存儲解決方案,本文就給大家介紹一下詳細(xì)介紹一下springboot整合mongodb使用,需要的朋友可以參考下
    2023-07-07
  • 詳解kafka中的消息分區(qū)分配算法

    詳解kafka中的消息分區(qū)分配算法

    kafka有分區(qū)機(jī)制,一個主題topic在創(chuàng)建的時候,會設(shè)置分區(qū)。如果只有一個分區(qū),那所有的消費(fèi)者都訂閱的是這一個分區(qū)消息;如果有多個分區(qū)的話,那消費(fèi)者之間又是如何分配的呢?本文就來為大家詳細(xì)講解一下
    2022-04-04
  • 深入剖析java中String、StringBuffer、StringBuilder的區(qū)別

    深入剖析java中String、StringBuffer、StringBuilder的區(qū)別

    下面小編就為大家?guī)硪黄钊肫饰鰆ava中String、StringBuffer、StringBuilder的區(qū)別。小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2016-05-05
  • SpringBoot集成圖片驗(yàn)證碼框架easy-captcha的詳細(xì)過程

    SpringBoot集成圖片驗(yàn)證碼框架easy-captcha的詳細(xì)過程

    本文介紹了如何將Easy-Captcha框架集成到SpringBoot項(xiàng)目中,實(shí)現(xiàn)圖片驗(yàn)證碼功能,Easy-Captcha是一款輕量級的開源驗(yàn)證碼框架,通過簡潔的API和高度可定制性,可以快速實(shí)現(xiàn)驗(yàn)證碼功能,文章詳細(xì)介紹了如何配置、生成和展示驗(yàn)證碼,并提供了Easy-Captcha的GitHub地址
    2025-03-03

最新評論

克山县| 南川市| 连南| 凤凰县| 乃东县| 恭城| 于田县| 湟中县| 邵武市| 普宁市| 宜宾市| 康乐县| 手游| 永济市| 道真| 惠水县| 定日县| 疏附县| 南充市| 墨脱县| 乐业县| 滨海县| 乌鲁木齐县| 连云港市| 井陉县| 临桂县| 五台县| 万宁市| 平和县| 蓝田县| 临洮县| 德江县| 辉南县| 桂东县| 昭苏县| 南城县| 巢湖市| 资兴市| 柞水县| 通州区| 宝山区|