java jdbc开启事务_spring jdbc 事务配置

配置WEB.XML

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_0.xsd"

version="3.0">

org.springframework.web.context.ContextLoaderListener

contextConfigLocation

classpath:application-config.xml

application-config.xml

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">

class="org.springframework.jdbc.datasource.DataSourceTransactionManager">

类上事务的声明:

@Transactional(rollbackFor=Exception.class)

//标注类中每一个方法都会启用事务,

// rollbackFor=Exception.class:指定当方法抛出Exception时事务回滚。

//@Transactional()未指定rollbackFor时,默认为当抛出RuntimeException时才事务回滚

public class TaskService {

@Transactional(rollbackFor=RuntimeException.class)

//以此事务形式启用事务,忽略类上声明的事务形式

public void triggerTask(){

}

//启用事务,继承类上定义的事务形式(@Transactional(rollbackFor=Exception.class))

public void triggerGeneratorTask(){

}

@Transactional(propagation= Propagation.NOT_SUPPORTED,readOnly=true)

//不启用事务

public List getRunningTask(){

return null;

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值