zoukankan      html  css  js  c++  java
  • spring boot 中 事务配置

    package org.whm.appcore;
    
    import java.util.Properties;
    
    import javax.sql.DataSource;
    
    import org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.beans.factory.annotation.Qualifier;
    import org.springframework.context.annotation.Bean;
    import org.springframework.jdbc.datasource.DataSourceTransactionManager;
    import org.springframework.stereotype.Component;
    import org.springframework.transaction.interceptor.TransactionInterceptor;
    
    @Component
    public class TxConfig {
    
        // 创建事务管理器
        @Bean(name = "txManager")
        public DataSourceTransactionManager getTx(@Autowired DataSource ds) {
            DataSourceTransactionManager dsTx = new DataSourceTransactionManager(ds);
            return dsTx;
        }
    
        // 创建事务通知。。
    
        @Bean(name = "txAdvice")
        public TransactionInterceptor getAdvisor(@Qualifier("txManager") DataSourceTransactionManager txManager)
                throws Exception {
            TransactionInterceptor tsi = new TransactionInterceptor();
            Properties properties = new Properties();
            properties.setProperty("get*", "PROPAGATION_REQUIRED,-Exception,readOnly");
            properties.setProperty("add*", "PROPAGATION_REQUIRED,-Exception,readOnly");
            properties.setProperty("save*", "PROPAGATION_REQUIRED,-Exception,readOnly");
            properties.setProperty("update*", "PROPAGATION_REQUIRED,ISOLATION_DEFAULT,-Exception,readOnly");
    
            tsi.setTransactionAttributes(properties);
            return tsi;
    
        }
    
        @Bean
        public BeanNameAutoProxyCreator txProxy() {
            BeanNameAutoProxyCreator creator = new BeanNameAutoProxyCreator();
            creator.setInterceptorNames("txAdvice");
            creator.setBeanNames("*Service", "*ServiceImpl");
            creator.setProxyTargetClass(true);
            return creator;
        }
    }
  • 相关阅读:
    运行 npm run dev 不能自动打开浏览器
    npm run dev 报错:Strings must use singlequote 的解决方法
    new和this
    new Object()、Object.create()、{}三种对象创建方式的区别
    Python 详解修饰器 附带 js使用修饰器
    Python
    react项目使用axios和Charles模拟数据接口
    react切换隐藏或显示状态(包含过渡动画)
    react里使用ref的几种方法
    js对象转数组
  • 原文地址:https://www.cnblogs.com/whm-blog/p/7262101.html
Copyright © 2011-2022 走看看