配置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;
}
}