注解式事务@Transactional(含配置文件)

注解式事务@Transactional一般添加在项目的服务类上,用于给服务加上事务

配置文件如下:applicationContext-tx.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:p="http://www.springframework.org/schema/p"

    xmlns:context="http://www.springframework.org/schema/context"

    xmlns:tx="http://www.springframework.org/schema/tx"

    xmlns:mvc="http://www.springframework.org/schema/mvc"

    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd

        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd

        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd

        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

     

    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> 

        <property name="dataSource" ref="dataSource" /> 

    bean> 

     

    <tx:annotation-driven transaction-manager="transactionManager"/>

beans>

你可能感兴趣的:(事务,注解)