NutzCN Logo
问答 nutz可以像spring那样配置全局事务级别吗?
发布于 2648天前 作者 老司机 2964 次浏览 复制 上一个帖子 下一个帖子
标签:

今天看到了个SSM项目,看到下面这段

<!-- 事务配置 -->
	<bean id="transactionManager"
		class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource">
			<ref local="dataSource" />
		</property>
	</bean>
	<bean id="transactionInterceptor"
		class="org.springframework.transaction.interceptor.TransactionInterceptor">
		<property name="transactionManager" ref="transactionManager"></property>
		<property name="transactionAttributes">
			<props>
				<prop key="get*">PROPAGATION_REQUIRED, readOnly</prop>
				<prop key="query*">PROPAGATION_REQUIRED, readOnly</prop>
				<prop key="find*">PROPAGATION_REQUIRED, readOnly</prop>
				<prop key="search*">PROPAGATION_REQUIRED, readOnly</prop>
				<prop key="list*">PROPAGATION_REQUIRED, readOnly</prop>
				<prop key="delOne*">PROPAGATION_REQUIRED, readOnly</prop>
				<prop key="*">PROPAGATION_REQUIRED , -Exception</prop>
			</props>
		</property>
	</bean>

说是配置全局的事务级别的,请问nutz有这样的方法吗?我也不想每次都new Atom

7 回复

文档aop那有声明式事务

@wendal 对了 这个配置可以配 nutzdao 的方法名称么,比如 insert / fetch /query /updateIgnoreNull

不知道配了可起效?

@wendal 那我 @Aop(TransAop.READ_COMMITTED)写在mainmodule上就是控制了全局的事务,然后还是遵循子module优先级高于mainmodule?

@qq_c1bab051 这种注解没有传播性。。。 你需要的json那种配置

给个案例吧(js配置文件,放置在resources/ioc/下)

/**
 * AOP事务
 */
var ioc = {

	// 声明5种事务等级对应的拦截器
	txNONE : {
        type : 'org.nutz.aop.interceptor.TransactionInterceptor',
        args : [0]
    },
    txREAD_UNCOMMITTED : {
        type : 'org.nutz.aop.interceptor.TransactionInterceptor',
        args : [1]
    },
    txREAD_COMMITTED : {
        type : 'org.nutz.aop.interceptor.TransactionInterceptor',
        args : [2]
    },
    txREPEATABLE_READ : {
        type : 'org.nutz.aop.interceptor.TransactionInterceptor',
        args : [4]
    },
    txSERIALIZABLE : {
        type : 'org.nutz.aop.interceptor.TransactionInterceptor',
        args : [8]
    },
    
    // transaction_aop
    $aop : {
    	type : 'org.nutz.ioc.aop.config.impl.ComboAopConfigration',
        fields : {
            aopConfigrations  : [
                {	
                	type : 'org.nutz.ioc.aop.config.impl.JsonAopConfigration',
                    fields : {
                        itemList : [
                                    ['com.xxx.biz.imp.+','.+','ioc:txREAD_COMMITTED']
		                ]
                    }
                },
                {
                	type : 'org.nutz.ioc.aop.config.impl.AnnotationAopConfigration'
        		}
            ]
        }
    }
};

MainModule注解@IocBy(type = ComboIocProvider.class, args = { "*json", "ioc/", "*anno", "com.xxx", "*tx" })

添加回复
请先登陆
回到顶部